Repository navigation
Description
Describe the Bug
In Payload 3.89.0, the enabled native Save Draft button can submit an earlier Lexical block value while a later edit in another block is still waiting for its nested Form's form-state response.
A deterministic component-level reproduction mounts the public RichTextField and BlocksFeatureClient, real Lexical BlockNodes/BlockComponents, their nested Payload Forms and TextFields, a parent document Form, and the native SaveDraftButton. No editor, field, node, provider, or submit implementation is patched or replaced.
Block A is edited and allowed to reach the parent document Form first. The parent is genuinely modified, so Save Draft is enabled in update mode. Block B's actual input is then edited, but its local form-state transport response is held. Clicking the native button sends a draft PATCH containing A's updated caption and B's previous caption, without waiting for B's response.
After releasing that response and letting the native block/editor/idle propagation complete, another native Save Draft sends both updated captions.
Expected: saving should either coordinate pending child-block changes before taking the document snapshot, or keep the save action unavailable until those changes have reached the document Form.
Actual: an enabled Save Draft completes with the earlier document snapshot while the later child-block change is pending.
Link to the code that reproduces this issue
The reproduction contains only synthetic captions and minimal test configuration. Save its five files together in a new empty directory, use Node.js 24.18.0 or later, and run npm install followed by npm test. It also passed after a separate fresh npm install --ignore-scripts --no-audit --no-fund; it does not rely on a pre-existing application's dependency installation.
Reproduction Steps
-
Run the linked characterization test. It seeds two instances of a minimal Lexical block with one text
captionfield each. -
Edit block A's real input to
First A caption edit. Complete its real child Form debounce, the local form-state response, BlockComponent node update, and outer RichText idle callback. Assert the parent is modified and holds A's updated value. -
Edit block B's distinct real input to
Second B caption edit. Let the real child Form invoke the localform-statetransport, but hold that response unresolved. The test also checks that A's input did not change. -
Click the actual enabled
#action-save-draftbutton. Capture its native PATCH FormData and inspect_payload. The caption projection is:[First A caption edit, Original B caption] -
Release B's form-state response, then let the actual BlockComponent
setFieldsupdate and outer RichText idle callback finish. Click native Save Draft again. Its next_payloadcontains:[First A caption edit, Second B caption edit]
The test intentionally passes when it observes this ordering gap; that is a characterization, not the desired fixed behavior. The child response is deferred to make the ordering deterministic, not to implement an application workaround.
Scope of the reproduction
- The public UI/editor path and real input/button interactions run in jsdom. CSS is inert; normal-shaped browser observers and Next navigation context values are supplied by the harness.
- Only server-function/fetch transport is synthetic: form-state returns the supplied field state, preference lookups return local 404s, and draft PATCHes return synthetic HTTP 200 responses. Real sockets and HTTP are blocked.
- No database, CMS server, environment file, account, or real content is involved. This does not establish a production data-loss incident.
- The complete hosted Edit view's
onChange/onSave, real server normalization/validation, database persistence/reload, Autosave and Publish are not tested. No claim is made that those other save paths were reproduced or fixed.
Source trace in the pinned packages
The child Form's debounced onChange awaits getFormState; BlockComponent then schedules editor.update(() => node.setFields(...)). The outer RichText Field defers its parent useField.setValue through useRunDeprioritized (idle timeout 500ms). Native Save Draft invokes the parent Form.submit, which snapshots its current fields before its beforeSubmit callbacks.
I could not find a documented public barrier that waits for both pending child Form responses and the outer RichText-to-Form bridge before that snapshot. An editor-state read alone would not await the child Form's request. If there is a supported coordination hook I have missed, guidance would be appreciated.
Possibly adjacent: #18425, but this report concerns nested Lexical block values in the outgoing document save, rather than late condition/validation metadata merging.
Which area(s) are affected?
area: ui; plugin: richtext-lexical
Environment Info
Payload / @payloadcms/ui / @payloadcms/next / @payloadcms/richtext-lexical: 3.89.0
@payloadcms/translations: 3.89.0
Lexical (installed dependency): 0.41.0
Next.js: 16.3.5
React / React DOM: 19.3.0
Node.js: 24.18.0
Vitest: 5.0.0
jsdom: 30.0.1
Vite: 8.1.5
These are the tested versions, not a claim about the latest v3/v4 release. No package patch or workaround has been applied.
Activity
aayushbaluni commentedon Oct 23, 2026
On your question — "if there is a supported coordination hook I have missed" —
beforeSubmitis the one that looks like it, and on currentmain(57f3909) it cannot serve as one. Two things inpackages/ui/src/forms/Form/index.tsxstand in the way, and they are worth knowing before anyone designs the barrier:1. The outgoing payload is snapshotted before
beforeSubmitruns.datais taken at 346 and is the object handed tocreateFormDataat 424. Nothing between those lines can change it exceptoverrides. So abeforeSubmithook that flushed pending child-block state would update the form state but not the request body.2.
beforeSubmit's returned state is discarded on the success path.revalidatedFormStateis dispatched only when validation fails. When it passes it is read forvalidand dropped, so the hook cannot contribute values even to the form state.3. Nothing registers a parent-level
beforeSubmitfor the editor. The threebeforeSubmitcall sites inrichtext-lexicalare all on nested forms —features/blocks/client/component/index.tsx:815,features/blocks/client/componentInline/index.tsx:509, andutilities/fieldsDrawer/DrawerContent.tsx:156. The parent document Form receives whatever the Edit view passes, which is not an editor flush.For completeness: the only
awaitbetween the click and the snapshot is the conditionalawait wait(100)at 342-343 underwaitForAutocomplete, so in the default path the snapshot is synchronous with the click. That matches the ordering your reproduction observes, and it means a fix cannot rely on incidental scheduling slack.That leaves the two strategies you named, and the choice between them is a product decision rather than a bug fix:
form-staterequests plus theuseRunDeprioritizedbridge inrichtext-lexical/src/field/Field.tsx, which the parentsubmitcan await before line 346. The deprioritized bridge is the awkward half:runDeprioritizedalready returns a promise, but the latest-invocation-wins cancellation means the promise for a superseded run never resolves, so a naiveawaitthere can hang.To be clear about what I checked: the three points above are read off
mainat57f3909and the line numbers are from that commit. I have not run the linked reproduction — the ordering it reports is consistent with the code path, but I am reporting the source trace, not a second reproduction.I am happy to implement either strategy, including the flush-promise fix the first one needs. Which would you accept? I would rather not guess at the semantics in a PR to the shared save path.