Skip to content

RTC can cause an unsaved change to persist and cause data loss from the original post #76402

Open

Description

@johnbillion

Description

It appears that an unsaved change can become "sticky" in the editor and prevent a user from being able to edit a post at its currently published state.

When this happens it's not clear how I can return to editing the post at its currently published state, and it's also not clear that a modified version of the post is being edited as opposed to the original.

Step-by-step reproduction instructions

  1. Edit a published post
  2. Make a change but do not save it
  3. Navigate away (dismiss the browser confirmation as necessary)
  4. Navigate back to the editor for that post and observe that your change persists

Depending on how quickly you return to the editor you may see your own avatar position at the point where you made a change.

Screenshots, screen recording, code snippet

You can repeat the process and easily end up with several of your own avatars on the editing screen:

Environment info

  • WordPress 7.0 beta 4

This can be reproduced on the make.wordpress.org sites too.

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 theissue type on Mar 11, 2026
  2. added
    [Type] Bug
    [Feature] Real-time Collaboration
    on Mar 11, 2026
  3. t-hamano commented on May 8, 2026

    @t-hamano
    Contributor
  4. moved this from 📥 Todo to 🦵 Punted to 7.1 in WordPress 7.0 Editor Taskson May 8, 2026
  5. giteshsarvaiya commented on Jul 1, 2026

    @giteshsarvaiya
    Contributor

    Reproduction notes

    I reproduced this, plus found a related bug from the same root cause. Sharing both here since they're connected.

    Case 1. Core bug — matches this issue exactly

    Steps:

    1. Make sure Real-Time Collaboration is enabled.
    2. Open an existing published post. Note its current content — e.g. a paragraph that just says hello.
    3. Click into that paragraph and type 123, so it now reads hello 123.
    4. Do not click Save/Update. Just leave the tab open for a few seconds (long enough for RTC's background sync to fire — a handful of seconds of inactivity is enough).
    5. Navigate away from the editor (e.g. back to the Posts list). If a browser "leave site / unsaved changes" prompt appears, confirm leaving.
    6. Reopen the same post in the editor.

    Expected: the paragraph shows hello (the actual published content).
    Actual: the paragraph shows hello 123 — the edit you never saved is back, as if it had been saved.

    Cause: RTC saves the full editor state to post meta (_crdt_document) continuously as you type, independently of clicking Save. Nothing clears that saved state when you leave without saving, so it gets replayed the next time you open the post.

    Case 2. Same bug, compounds with more typing

    Steps:

    1. Repeat steps 1-3 above (hello → hello 123).
    2. This time, wait about a minute before doing anything else (long enough for WordPress's own separate autosave to also fire in the background).
    3. Type 123 again, so the paragraph now reads hello 123 123.
    4. Leave the page immediately without saving.
    5. Reopen the post.

    Result: shows hello 123 123. Same bug as case 1 — just confirms it's consistent and reflects whatever was last typed, no matter how much editing happened.

    Case 3. Related but separate: restoring the server-side autosave makes it worse

    Not part of the original report, but found while testing case 1. Note: WordPress actually has two separate autosave notices — a browser-local one ("The backup of this post in your browser is different...") and a server-side one ("There is an autosave of this post that is more recent..."). Restoring the browser-local backup works fine and doesn't show this bug. It's specifically the server-side autosave restore that causes it:

    Steps:

    1. Follow case 1's steps until you reopen the post and see the resurfaced hello 123.
    2. At this point WordPress also shows its own, separate "there is a more recent autosave" notice (this is a normal WordPress feature, unrelated to RTC on its own).
    3. Click the "View the autosave" link/button in that notice.

    Result: hello 123 becomes hello 123 123 — an extra copy gets added. If you repeat the whole cycle again (edit, leave, reopen, restore the autosave again), it adds yet another copy (hello 123 123 123, and so on).

    Cause: clicking "View the autosave" loads a second, separately-saved copy of the same edit (WordPress's own server-side autosave, captured independently of RTC). When that gets combined with RTC's already-saved state, the two aren't recognized as the same edit — instead of merging cleanly, the edit gets added again.

    Summary

    • case 1 matches what's described in this issue.
    • case 2 is the same bug as case 1, just repeated to confirm it's consistent.
    • case 3 is a related but separate bug found during testing — happy to file it separately if that's preferred.

    I'm looking into a fix — more in the next comment.

    version: 7.1-alpha-62588

  6. giteshsarvaiya commented on Jul 1, 2026

    @giteshsarvaiya
    Contributor

    @maxschmeling @ellatrix @mmtr — flagging that I've been digging into this (details
    in the comment above — case 1 is the one that matches this issue exactly; case 3 is
    a related finding from the same investigation, maybe we can open a new issue for it).

    Case 1 appears to stem from _applyPersistedCrdtDoc unconditionally replaying
    persisted CRDT state on load via Y.applyUpdateV2, with no check for whether that
    state was ever actually saved or discarded. I've confirmed this mutation happens,
    but haven't yet fully traced how it propagates into what's rendered in the editor —
    still working through that.

    Separately, I found a concrete, isolated bug that looks related to case 3's
    duplication: in the same function's reconciliation step, when 'blocks' comes back
    as an invalidated key, it does changes[key] = record[key] — but REST post records
    don't expose a blocks field (only content), so this always evaluates to
    undefined and wipes the CRDT blocks array instead of correctly restoring it. This
    part is confirmed by reading the code; I haven't yet confirmed via a debugger/test
    that it's the full explanation for the compounding duplication, just that it's a
    real bug in that path.

    I'd like to start with that isolated record['blocks'] fix first (small, clearly
    scoped, easy to write a regression test for), then dig further into case 1's
    resurfacing with an eye toward discard-driven cleanup of the persisted
    _crdt_document meta — but want to nail down the exact mechanism with a test before
    proposing that fix.

    Let me know if there's a preferred approach, known constraints, or in-flight work I
    should be aware of first.

  7. giteshsarvaiya commented on Jul 8, 2026

    @giteshsarvaiya
    Contributor

    Hi @maxschmeling @ellatrix @mmtr ,
    Filed the Case 3 duplication bug separately as #80004 (distinct root cause, small isolated fix) and opened a PR for it: #80011

    To be clear — this doesn't address the core issue described here (Case 1, the unsaved-edit resurfacing on reopen); that's still the unconditional CRDT replay-on-load issue, and I'm holding off proposing a fix for that until I can nail down the exact mechanism with a test, or hear back on preferred approach.

  8. t-hamano commented on Jul 9, 2026

    @t-hamano
    Contributor

    Since the collaborative editing feature has been punted from the 7.1 release, I would like to change the status of this issue on the project board accordingly.

  9. moved this from 📥 Todo to 🦵 Punted to 7.2 in WordPress 7.1 Editor Taskson Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Real-time Collaboration[Type] Bug

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions