Skip to content

Refactor edit/render field tranforms - #1796

Open
FedericoBonel wants to merge 4 commits into
fede/puck-542-support-field-transforms-within-renderfrom
fede/refactor-field-transforms
Open

Refactor edit/render field tranforms#1796
FedericoBonel wants to merge 4 commits into
fede/puck-542-support-field-transforms-within-renderfrom
fede/refactor-field-transforms

Conversation

@FedericoBonel

@FedericoBonel FedericoBonel commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

NOTE: Requires changes from #1793

Description

This PR refactors the codebase to centralize field transformation in the editor and render paths.

While working on #1793, I realized there were a lot of inconsistencies and redundancies between the root render path and the component render path, so I decided to try to centralize the field transformation logic in a single hook.

I also realized the render path needed some cleanup, since useSlots and useRichtextTransforms were always called in the same order, and the goal of the double call is to apply all the required transforms for the render path. Since user transforms are now also available in Render, it made sense to extract that into a central hook that combines the logic and centralizes it in one place for parity with the edit path.

Changes made

  • Added a new useEditorProps hook that implements the logic for orchestrating editor field transforms for a single component.
  • Added a new useRenderProps hook that implements the logic for orchestrating render field transforms for a single component.
  • Removed the unnecessary WithPuckProps from useRichtextProps.

Summary by CodeRabbit

  • Improvements
    • Improved consistency when rendering components, slots, rich text, and root content across editor, preview, and server-rendered experiences.
    • Consolidated field transformations so editing and rendering apply component properties more reliably.
    • Preserved read-only and loading behavior while simplifying property handling.
    • Maintained existing rich-text discovery and slot rendering behavior.

@vercel

vercel Bot commented Aug 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
puck-demo Ready Ready Preview Aug 12, 2026 3:19pm
puck-docs Ready Ready Preview Aug 12, 2026 3:19pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 51676671-7a0f-4827-89a4-beb27aa5a821

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f342689b-40ce-48ce-a13e-7823a04585c1

📥 Commits

Reviewing files that changed from the base of the PR and between 1115986 and e12d148.

📒 Files selected for processing (9)
  • packages/core/components/DropZone/index.tsx
  • packages/core/components/Puck/components/Preview/components/edit-page.tsx
  • packages/core/components/Render/index.tsx
  • packages/core/components/RichTextEditor/lib/use-richtext-props.tsx
  • packages/core/components/ServerRender/index.tsx
  • packages/core/components/SlotRender/server.tsx
  • packages/core/lib/field-transforms/use-editor-props.tsx
  • packages/core/lib/field-transforms/use-render-props.tsx
  • packages/core/lib/use-slots.tsx
💤 Files with no reviewable changes (1)
  • packages/core/lib/use-slots.tsx

📝 Walkthrough

Walkthrough

The change centralizes editor and render-time field transformation in useEditorProps and useRenderProps. Drop-zone, preview, client rendering, server rendering, and slot rendering now use the centralized prop flows.

Changes

Unified prop transformation

Layer / File(s) Summary
Transformation hooks
packages/core/lib/field-transforms/*, packages/core/components/RichTextEditor/lib/use-richtext-props.tsx
Adds useEditorProps and useRenderProps. Updates rich-text prop handling to accept plain props.
Editor integration
packages/core/components/DropZone/index.tsx, packages/core/components/Puck/components/Preview/components/edit-page.tsx
Replaces local editor transform assembly with useEditorProps for component and root properties.
Rendering integration
packages/core/components/Render/index.tsx, packages/core/components/ServerRender/index.tsx, packages/core/components/SlotRender/server.tsx, packages/core/components/DropZone/index.tsx
Uses useRenderProps for slot and rich-text processing. Removes the deleted useSlots flow and separate rich-text prop merging.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Render
  participant useRenderProps
  participant useRichtextProps
  participant Component
  Render->>useRenderProps: build root render props
  useRenderProps->>useRichtextProps: resolve rich-text props
  useRenderProps-->>Render: return consolidated props
  Render->>Component: render with consolidated props
Loading

Possibly related PRs

Suggested reviewers: chrisvxd

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the central refactor of edit and render field transforms, despite a minor spelling error in “tranforms”.
Description check ✅ Passed The description clearly explains the refactor and lists the main changes, but it does not include the required issue-closing line or testing details.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fede/refactor-field-transforms

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors core editor and render pipelines to centralize field transformation logic, aiming to ensure consistent behavior across root rendering, component rendering, and slot/richtext handling in both editor and render contexts.

Changes:

  • Introduces useEditorProps to orchestrate editor-side field transforms (slots, inline text, richtext, plugin transforms, and user transforms) with read-only/loading state.
  • Introduces useRenderProps to orchestrate render-side field transforms (slots + user transforms, then richtext conversion) for both CSR Render and server/RSC render paths.
  • Removes the now-redundant useSlots helper and simplifies useRichtextProps typing by dropping WithPuckProps.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/core/lib/use-slots.tsx Removes legacy slot+transform hook now superseded by centralized render/editor hooks.
packages/core/lib/field-transforms/use-render-props.tsx Adds unified render-side prop transformation (slots + user transforms + richtext).
packages/core/lib/field-transforms/use-editor-props.tsx Adds unified editor-side prop transformation (slots + inline/richtext + plugin + user transforms).
packages/core/components/SlotRender/server.tsx Switches server slot rendering to use useRenderProps for consistent transforms.
packages/core/components/ServerRender/index.tsx Switches server render paths to useRenderProps and removes separate richtext pass.
packages/core/components/RichTextEditor/lib/use-richtext-props.tsx Updates typing to remove WithPuckProps dependency.
packages/core/components/Render/index.tsx Switches client Render to useRenderProps and removes separate richtext pass.
packages/core/components/Puck/components/Preview/components/edit-page.tsx Switches edit preview root prop orchestration to useEditorProps.
packages/core/components/DropZone/index.tsx Switches editor and render DropZone item prop orchestration to useEditorProps / useRenderProps.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/core/lib/props/editor/use-editor-props.tsx
Comment thread packages/core/lib/field-transforms/use-editor-props.tsx Outdated

@chrisvxd chrisvxd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff!

@@ -5,7 +5,6 @@ import {
FieldTransforms,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second commit message isn't escaped so just shows "chore: remove unnecesary from" (also typo in unnecessary)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it!

@@ -0,0 +1,63 @@
// This file should avoid importing any non RSC friendly code (state, effects, context, etc.), as it is used in both RSC and CSR contexts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These do various bits beyond just field transforms so I think they could probably move up a directory to lib

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to ./lib/props/editor and ./lib/props/render

@FedericoBonel

Copy link
Copy Markdown
Collaborator Author

Addressed @chrisvxd!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants