Refactor edit/render field tranforms - #1796
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughThe change centralizes editor and render-time field transformation in ChangesUnified prop transformation
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
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
useEditorPropsto orchestrate editor-side field transforms (slots, inline text, richtext, plugin transforms, and user transforms) with read-only/loading state. - Introduces
useRenderPropsto orchestrate render-side field transforms (slots + user transforms, then richtext conversion) for both CSRRenderand server/RSC render paths. - Removes the now-redundant
useSlotshelper and simplifiesuseRichtextPropstyping by droppingWithPuckProps.
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.
e12d148 to
b298c87
Compare
| @@ -5,7 +5,6 @@ import { | |||
| FieldTransforms, | |||
There was a problem hiding this comment.
The second commit message isn't escaped so just shows "chore: remove unnecesary from" (also typo in unnecessary)
| @@ -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. | |||
There was a problem hiding this comment.
These do various bits beyond just field transforms so I think they could probably move up a directory to lib
There was a problem hiding this comment.
Moved it to ./lib/props/editor and ./lib/props/render
b298c87 to
7ba93e2
Compare
7ba93e2 to
4c6b900
Compare
|
Addressed @chrisvxd! |
5d053ab to
c1ec977
Compare
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
rootrender 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
useSlotsanduseRichtextTransformswere 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 inRender, 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
useEditorPropshook that implements the logic for orchestrating editor field transforms for a single component.useRenderPropshook that implements the logic for orchestrating render field transforms for a single component.WithPuckPropsfromuseRichtextProps.Summary by CodeRabbit