Repository navigation
fix(richtext-lexical): preserve block data on remount - #17957
Merged
Merged
Conversation
Contributor
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
paulpopus
force-pushed
the
codex/poss-157-lexical-block-remount
branch
from
August 27, 2026 17:12
eee628b to
6c4331a
Compare
|
FYI: have this problem as well. A fix would be greatly appreciated |
|
Hello there, same problem for me. |
ClementNumericite
added a commit
to Numericite/ditnd-unification-site
that referenced
this pull request
Sep 23, 2026
Editing an accordion item in a WYSIWYG page, switching admin tab and coming back dropped everything added since the page load, before even saving. On remount, BlockComponent rebuilds its form state from the server-rendered snapshot and only refreshes top-level keys (`fieldName in formData`). The accordion block holds an array (`items`), whose sub-fields live under dotted paths (`items.0.content`): they are never refreshed, so the stale snapshot wins and is then written back to the lexical node. Backport payloadcms/payload#17957 to 3.89.0 via patch-package. The new getCachedFormStateIfDataMatches resolves dotted paths against the current node data, skips array/blocks parents whose value is a row list, and only falls back to a server rebuild when the row topology itself changed. Upstream issue payloadcms/payload#17894. Drop this patch once #17957 ships. Co-Authored-By: Claude <[email protected]>
ClementNumericite
added a commit
to Numericite/ditnd-unification-site
that referenced
this pull request
Sep 23, 2026
Editing an accordion item in a WYSIWYG page, switching admin tab and coming back dropped everything added since the page load, before even saving. On remount, BlockComponent rebuilds its form state from the server-rendered snapshot and only refreshes top-level keys (`fieldName in formData`). The accordion block holds an array (`items`), whose sub-fields live under dotted paths (`items.0.content`): they are never refreshed, so the stale snapshot wins and is then written back to the lexical node. Backport payloadcms/payload#17957 to 3.89.0 via patch-package. The new getCachedFormStateIfDataMatches resolves dotted paths against the current node data, skips array/blocks parents whose value is a row list, and only falls back to a server rebuild when the row topology itself changed. The admin does not load dist/features/**, it loads the prebuilt dist/exports/client bundles, which carry their own copy of the component. So the same fix is applied there too, inlined as __pl17957 in exports/client/index.js (BlockComponent) and exports/client/chunk-XFA5M7FY.js (InlineBlockComponent). Patching only the unbundled sources has no effect. Upstream issue payloadcms/payload#17894. Drop this patch once #17957 ships. Co-Authored-By: Claude <[email protected]>
Written with AI
Written with AI
Written with AI
paulpopus
marked this pull request as ready for review
September 24, 2026 11:33
Written with AI
paulpopus
requested review from
JarrodMFlesch and
jacobsfletch
as code owners
September 24, 2026 21:42
Written with AI
AlessioGr
approved these changes
Oct 1, 2026
Contributor
|
🚀 This is included in version v4.0.0-canary.38 |
This was referenced Nov 6, 2026
jacobsfletch
added a commit
that referenced
this pull request
Nov 7, 2026
Requires #19425. Prerequisite for #19343. Uses `getDataFromFormState` for regular and inline Lexical blocks, replacing the separate reducer introduced in #17957. Lexical now follows the same form-state rules as the rest of the admin panel, including keeping keys with `undefined` values. ## Notable changes ### Empty arrays when unflattening Lexical and the rest of the admin panel previously handled empty arrays differently. Lexical could omit the field, while regular form data could contain its row count (`0`). This normalizes form-state behavior across Lexical and the rest of the admin panel so empty arrays come through as `[]` in both. Explicit empty arrays are now preserved during unflattening when `overwrite: false` (the default), so stale child fields can't bring deleted rows back. `overwrite: true` lets child fields populate the array: ```ts unflatten({ items: [], 'items.0.title': 'Stale' }) // { items: [] } unflatten({ items: [], 'items.0.title': 'Stale' }, { overwrite: true }) // { items: [{ title: 'Stale' }] } ``` ### disableFormData `disableFormData` no longer controls how rows are serialized and instead does what its name implies by keeping a field's value out of form submissions. `getDataFromFormState` now builds array and blocks data without needing `disableFormData` to hide the row count: ```ts getDataFromFormState( { items: { // disableFormData: true, // No longer needed to omit "value: 1" rows: [{ id: 'row-1' }], value: 1, }, 'items.0.id': { value: 'row-1' }, 'items.0.title': { value: 'Hello' }, }, true, ) // { items: [{ id: 'row-1', title: 'Hello' }] } ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getFormStatepipeline for changed arrays, nested blocks, objects, null transitions, and metadataRoot cause
The remount initializer tried to merge nested node data into a flat cached
FormStateby matching top-level keys. Dotted array-row fields were never refreshed or created, and the array parent received the full array where the form-state contract expects a row count. The truncated state could then be written back to the Lexical node and autosaved.The fix avoids reconstructing schema-derived state from runtime value shapes. When cached values differ from the node, both block component variants rebuild through Payload's authoritative form-state builder.
Verification
pnpm test:unit packages/richtext-lexical/src— 9 files, 89 tests passedpnpm build:richtext-lexical— 4/4 tasks successfulgit diff --check— passedFixes #17894
Linear: https://linear.app/figma/issue/POSS-157