fix(ui): reject stale autosave responses that overwrite form values#17455
Open
jacobsfletch wants to merge 2 commits into
Open
fix(ui): reject stale autosave responses that overwrite form values#17455jacobsfletch wants to merge 2 commits into
jacobsfletch wants to merge 2 commits into
Conversation
Autosave and form-state requests run on independent client queues and can resolve out of order. `mergeServerFormState` accepted a server value for any non-`isModified` field, so a straggler response whose payload was built from an older snapshot could clobber a value a later response already wrote. For auto-tracked fields like the native slug (never marked modified), the stale value was then re-sent and frozen by the field `beforeChange` hook, persisting the wrong value. Tags each value-accepting submit with a monotonic `requestSequence` in send order and records the writing sequence on each field as `valueSequence`. `mergeServerFormState` now rejects a response older than the sequence that last wrote the field. `valueSequence` is stripped before form state is serialized to the server, so it adds no wire cost.
…uence Replaces the per-field `isModified` flag with a monotonic sequence clock shared by local edits and value-accepting submits. `isModified` only guarded the single most-recently-edited field (it was cleared on every other field), so editing one field then another could let a background autosave response clobber the first. Each local edit and each accepted server response now stamps the field's `valueSequence`; `mergeServerFormState` accepts an autosave value only when the response's `requestSequence` is not older than the field's current sequence. This one check subsumes the old `isModified` guard and protects every recently-edited field independently, while still rejecting stale, out-of-order responses.
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.
|
This was referenced Jul 24, 2026
Closed
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.
Concurrent autosave events that resolve out of order could overwrite form values with stale, server-computed data. Most visibly, the native
slugfield would freeze to a partial value when typing quickly with a fast autosave interval on a throttled network.Root cause:
slugare never marked modified, so a stale response — computed from an earlier, partial title — was always accepted.beforeChangehook read it as a manual edit and froze it, persisting the wrong slug.The fix is to tag each value-accepting submit with a monotonic
requestSequenceand stamp the writing sequence onto each field asvalueSequence. A server value is accepted only when the response is no older than the field's current sequence.Huge win: this also replaces the per-field
isModifiedflag (which was a hack introduced in #13460).isModifiedonly protected the single most-recently-edited field from being overwritten by server computed values. The sequence approach protects every recently-edited field, covering both stale responses and values edited mid-request with one check.Note:
valueSequenceis stripped before form state is sent to the server, so it adds no request payload.Fixes #15430.