Repository navigation
Conversation
… changes are batched The selection history was updated in a timeout, so when several queued changes were applied in one go, an undo level saved the selection from before all of them. Update it when the change's transaction ends, after the undo manager has saved its meta. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🤖 PR meta 🤖📦 Bundle sizeSize Change: +15 B (0%) Total Size: 8.56 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Custom Completer: should allow option selection via keypress event in
|
This branch has not been deployed
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.
What?
With real-time collaboration, undo restores the caret from before the change even when several changes were applied to the shared document in one batch.
This fixes the most frequent CI flake right now, "Collaboration - Undo/Redo › Undo restores the post selection when another synced entity is loaded": it needed a retry in 8 of the last 10 trunk runs (2026-10-29).
Why?
In the test, the user types "abcdef", moves the caret to 3, presses Enter, then undoes. The caret should go back to 3 but lands at 6. A trace of a failing run showed:
setTimeout. Playwright presses keys back to back and Chromium runs input before timers, so the typing, the caret moves and Enter were all applied in one batch after Enter.setTimeout(applyPostChangesToCRDTDoc), so none of them had been recorded when the batch reached Enter's change.Locally it failed 6 of 10 runs on trunk. CI only started hitting it on Oct 23, when "Try: Run e2e tests in parallel, on one wp-env site per two cores" (#85420) put more load on each runner. A person typing doesn't batch changes like this, but a busy main thread can.
How?
Record the selection when the change's Yjs transaction ends (
ydoc.once( 'afterTransaction' )) instead of in a timeout. The undo manager saves its undo meta in its ownafterTransactionlistener, which was added first, so the meta still holds the selection from before the change, as the timeout intended.Testing Instructions
expected [ undefined ]) and passes here.WP_BASE_URL=<site> npm run test:e2e -- --project=chromium --retries=0 --repeat-each=10 test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts -g "Undo restores the post selection": 6 of 10 failed on trunk, 10 of 10 pass here.core-dataandsyncunit tests.There is no Playground link or screenshot: the bug only shows when changes arrive faster than the sync manager's timeout, which can't be done by hand, so the tests above cover it.
Use of AI Tools
Investigated and written with Claude Code.
🤖 Generated with Claude Code