Skip to content

RTC: restoring a server-side autosave duplicates block content instead of merging it #80004

Open

Description

@giteshsarvaiya

Description


[NOTE]:
This issue appears to be intermittent and has been difficult to reproduce consistently.

  • I originally observed the behaviour and have been able to reproduce it only occasionally (approximately 7–8 times out of 30–40 attempts).
  • At the time of writing, neither I nor the maintainers have found a reliable set of reproduction steps.
  • Based on the code path, I suspect this may be related to a race condition, but this is currently a hypothesis rather than a confirmed root cause.
  • If I discover a reliable reproduction scenario or gather additional debugging information, I will update this issue accordingly.

Leaving the issue open so future observations and debugging information can be collected.


Found while investigating #76402. This is a related but separate bug — filing separately since it has its own distinct root cause and a small, isolated fix.

Root cause: in _applyPersistedCrdtDoc (packages/sync/src/manager.ts), when blocks is invalidated, the fix reads record['blocks'] — always undefined since REST records only expose content. That undefined hits crdt.ts's 'blocks' case, which has a correct fallback (re-derive from content) but only takes it if content is also passed — which it isn't, so it wipes-and-rebuilds instead, causing the duplication.

Suggested fix: also pass record.content along when blocks is invalidated, so the existing correct fallback path gets used.

Step-by-step reproduction instructions

Steps to reproduce:

  1. Enable RTC. Open a published post with a paragraph that says hello.
  2. Type 123 → hello 123. Don't save.
  3. Wait ~1 minute (for WP's own server-side autosave to fire).
  4. Leave without saving, reopen the post — hello 123 resurfaces (matches RTC can cause an unsaved change to persist and cause data loss from the original post #76402), plus a "there is a more recent autosave" notice.
  5. Click "View the autosave".

Expected: stays hello 123. Actual: becomes hello 123 123, and repeating the cycle keeps stacking duplicates.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. added
    [Type] Bug
    on Jul 8, 2026
  2. giteshsarvaiya commented on Jul 8, 2026

    @giteshsarvaiya
    ContributorAuthor

    Working on this and raising a PR soon

  3. added
    [Status] In Progress
    on Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

[Status] In Progress[Type] Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions