fix(ui): prevent false positive stale data modal on autosave-enabled documents#15817
Open
PatrikKozak wants to merge 2 commits intomainfrom
Open
fix(ui): prevent false positive stale data modal on autosave-enabled documents#15817PatrikKozak wants to merge 2 commits intomainfrom
PatrikKozak wants to merge 2 commits intomainfrom
Conversation
…-stale-check-for-autosave
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 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
Temporarily disable stale data checking for autosave-enabled collections and globals to prevent false positives from race conditions.
Problem
When autosave is enabled (collections or globals), rapid edits trigger a race condition between autosave completion and onChange debounce, causing the "Document Modified" modal to incorrectly appear for the same user.
Approaches Considered
Several approaches were explored to distinguish between a user's own autosaves and another user's changes:
Track autosave queue status: Add an
autosaveQueuedflag to skip stale checks when autosave is processing. This fixes the false positive (same user seeing their own changes as stale), but creates false negatives in multi-user scenarios. When User 2 starts typing, their own autosave could queue before onChange fires, causing the check to skip even when User 1 has legitimately modified the document.Grace period after page load: Skip stale checks for X seconds after opening a document. This is an arbitrary time-based workaround that doesn't address the root cause and has unreliable edge cases (what if autosave takes longer than the grace period?).
Shared queue between Form and Autosave: Have both components use the same task queue to coordinate timing. While architecturally sound, this requires a major refactor and still doesn't solve the fundamental issue that autosave's potentially shorter debounce causes it to queue before onChange.
Immediate stale check without debounce: Perform the stale data check directly in the Form component on every keystroke instead of waiting for the debounced onChange. This could work but duplicates onChange logic, requires watching formState changes without debounce, and could cause performance issues.
Combined approaches: Mix multiple approaches (e.g., autosaveQueued + grace period). This adds significant complexity without fully solving the problem - still vulnerable to edge cases and race conditions.
All approaches were flawed because they tried to work around the timing issue rather than addressing the fundamental problem: we can't reliably distinguish between a user's own autosaves and another user's changes without tracking who made each change.
Solution
Disable stale data checking when:
versions.drafts.autosaveis configuredversions.drafts.autosaveis configuredAutosave-enabled documents already have frequent saves for conflict resolution.
Future Work (v4.0)
Implement proper
updatedBytracking to compare current user vs last editor. This is the correct solution but requires breaking schema changes.Changes
hasAutosaveEnabled(docConfig)returns trueFixes #15803