Skip to content

Rich Text: Mark undo levels from the change handler - #86007

Merged
ellatrix merged 2 commits into
trunkfrom
claude/charming-carson-ea18d5
Oct 30, 2026
Merged

ellatrix merged 2 commits into
trunkfrom
claude/charming-carson-ea18d5

Conversation

@ellatrix

@ellatrix ellatrix commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

What?

Follow up to #57435 and #83463.

Rich text fields decide undo levels when they change, instead of after every render. An unselected paragraph's rich text drops 6 hooks (74 to 68), including a layout effect that ran after every render.

Why?

Every rich text field paid for undo grouping on mount and on every render, but only the field being edited changes. Watching renders also let changes from outside the field end the current undo level, such as leaving bold with the arrow key while typing.

How?

  • A change starts a new undo level when the field's last change was a format change, or was a second or more ago. The field marks the last change as persistent right before applying the new one, so there is no timer.
  • Formatting across blocks changes blocks outside any field, so it marks its own change. Without this, bold then italic across blocks undo together.
  • Marking right after the change doesn't work: useRichText calls onChange inside registry.batch, so the change would get its own level, and Cmd+B with no selection would leave an undo level that changes nothing.
  • Removes useMarkPersistent, its unit test and types.

Changed behaviour: leaving a format with the arrow key between typing no longer ends the undo level, the same as any other arrow key. The new e2e test for this fails on trunk.

Time per block (CPU, 500 paragraphs, 8 paired rounds): trunk about 78.2 µs, this PR about 78.6 µs, with ±2 µs noise on a loaded machine. Not measurable.

Testing Instructions

Open in Playground: a post with a paragraph that ends in bold text and a plain one, open in the editor.

  1. In the paragraph, press End, then ArrowLeft (the caret stays, inside the bold text). Type "x", press ArrowRight, type "y". Press Cmd+Z: both "x" and "y" are removed. On trunk, only "y" is.
  2. Type a few words, wait a second, type a few more. Press Cmd+Z: only the words after the pause are removed.
  3. Select a word and press Cmd+B. Press Cmd+Z: the bold is removed and the text stays.

Testing Instructions for Keyboard

All steps above use the keyboard only.

Screenshots or screencast

No visual change: this changes which edits undo together. The e2e tests in undo.spec.js cover it.

Use of AI Tools

Written with Claude Code (Claude Opus 5.5), directed by @ellatrix.

🤖 Generated with Claude Code

ellatrix and others added 2 commits October 29, 2026 20:30
Each rich text field ran useMarkPersistent on every render: a debounced
function, a layout effect comparing snapshots, and five other hooks.
Only the selected field changes, so decide the undo level when it does:
a change starts a new level when the field's last change was a format
change or more than a second ago. Cross-block formatting marks its own
change, since no field sees it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ellatrix ellatrix added [Type] Performance Related to performance efforts [Package] Block editor /packages/block-editor labels Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ellatrix <ellatrix@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: -124 B (0%)

Total Size: 8.56 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 541 kB -124 B (-0.02%)

be9a263 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric bd60937 trunk % Change
timeToFirstByte 55.4 ms +9.75% -3.16% 55.85 ms +7.25% -3.85% -0.81%
largestContentfulPaint 92 ms +8.7% -4.35% 92 ms +4.35% -4.35% 0%
lcpMinusTtfb 35.3 ms +19.83% -4.11% 35.95 ms +7.09% -3.89% -1.81%
wpBeforeTemplate 29.22 ms +13.18% -1.37% 28.89 ms +13.74% -1.42% 1.14%
wpTemplate 21.95 ms +4.51% -3.55% 22.26 ms +2.65% -4.72% -1.39%
wpTotal 51.45 ms +9.56% -2.99% 52.05 ms +7.38% -3.9% -1.15%
wpMemoryUsage 7.70 MB +0% -0% 7.67 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric bd60937 trunk % Change
timeToFirstByte 47.05 ms +10.1% -2.44% 45.9 ms +6.97% -0.87% 2.51%
largestContentfulPaint 104 ms +3.85% -3.85% 100 ms +4% -0% 4%
lcpMinusTtfb 54.6 ms +2.66% -1.28% 54.25 ms +1.01% -1.84% 0.65%
wpBeforeTemplate 26.88 ms +13.8% -0.52% 26.57 ms +1.39% -1.43% 1.17%
wpTemplate 16.62 ms +2.65% -4.39% 16.36 ms +4.65% -2.69% 1.59%
wpTotal 43.88 ms +8.55% -2.89% 42.88 ms +7.44% -0.96% 2.33%
wpMemoryUsage 6.39 MB +0% -0% 6.36 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric bd60937 trunk % Change
mediaProcessingJpeg 402.96 ms +1.2% -1.69% 403 ms +1.04% -0.61% -0.01%
mediaProcessingAvif 6155.64 ms +0.19% -0.18% 6178.78 ms +0.46% -0.42% -0.37%
mediaProcessingJpegToAvif 4217.23 ms +0.11% -0.14% 4222.06 ms +0.17% -0.53% -0.11%

media-upload

Metric bd60937 trunk % Change
jpegUploadProcessing 1471.77 ms +34.23% -1.11% 1496.35 ms +29.49% -1.84% -1.64%
pngUploadProcessing 180.87 ms +39.74% -9.87% 225.2 ms +24.46% -19.53% -19.68%
largeJpegUploadProcessing 1482.91 ms +31.09% -2.2% 1477.95 ms +31.8% -1.87% 0.34%
multipleImageUploadProcessing 2022.51 ms +1.55% -0.4% 2028.08 ms +0.45% -1.08% -0.27%

post-editor

Metric bd60937 trunk % Change
serverResponse 351.51 ms +8.54% -2.08% 371.6 ms +1.88% -5.77% -5.41%
firstPaint 226.52 ms +75.62% -21.44% 403.82 ms +1.89% -32.44% -43.91%
domContentLoaded 684.94 ms +2.52% -0.99% 693.62 ms +1.13% -1.61% -1.25%
loaded 685.71 ms +2.53% -0.98% 694.51 ms +1.11% -1.63% -1.27%
firstContentfulPaint 401.06 ms +2.16% -0.81% 412.67 ms +1.13% -1.95% -2.81%
firstBlock 1999.72 ms +1.45% -1.5% 2047.32 ms +0.7% -0.44% -2.32%
type 16 ms +6.75% -9.56% 15.13 ms +6.61% -8.66% 5.75%
typeWithoutInspector 14.75 ms +10.78% -5.56% 14.93 ms +8.1% -6.83% -1.21%
typeWithTopToolbar 19.04 ms +5.46% -1.21% 19.27 ms +6.85% -5.86% -1.19%
typeContainer 7.22 ms +8.31% -4.16% 7.6 ms +6.32% -12.11% -5%
focus 93.33 ms +1.79% -3.85% 94.83 ms +3.52% -6.83% -1.58%
firstFocus 207.28 ms +0% -0% 206.54 ms +0% -0% 0.36%
selectAll 255.51 ms +1.9% -3.02% 294.41 ms +1.89% -7.76% -13.21%
undo 25.29 ms +4.15% -7.24% 24.65 ms +4.38% -2.84% 2.6%
listViewOpen 62.95 ms +7.88% -7.31% 60.26 ms +7.14% -7.68% 4.46%
inserterOpen 32.79 ms +9.45% -3.81% 35.65 ms +5.75% -4.26% -8.02%
inserterHover 9.08 ms +20.04% -6.28% 10.16 ms +9.45% -7.38% -10.63%
inserterSearch 7.71 ms +1.04% -3.24% 7.42 ms +5.93% -5.66% 3.91%
loadPatterns 531.68 ms +2.24% -3.27% 520.5 ms +6.21% -3.04% 2.15%
wpTotal 342.25 ms +8.85% -2.04% 363.13 ms +1.71% -6.16% -5.75%
wpMemoryUsage 14.73 MB +0% -0% 14.72 MB +0% -0% 0.1%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric bd60937 trunk % Change
serverResponse 526.16 ms +2.2% -6.24% 538.5 ms +4.34% -4.71% -2.29%
firstPaint 254.91 ms +8.26% -16.06% 275.99 ms +9.49% -8.25% -7.64%
domContentLoaded 913.66 ms +0.77% -0.75% 920.5 ms +1.82% -1.55% -0.74%
loaded 914.81 ms +0.75% -0.75% 921.78 ms +1.81% -1.58% -0.76%
firstContentfulPaint 500.27 ms +2.1% -2.21% 516.39 ms +3.47% -1.9% -3.12%
firstBlock 3790.91 ms +0.15% -1.2% 3737.07 ms +0.88% -0.71% 1.44%
type 17.65 ms +4.87% -3.51% 18.66 ms +4.82% -8.84% -5.41%
navigate 118.09 ms +6.66% -2.51% 118.2 ms +9.5% -2.01% -0.09%
loadPatterns 1166.61 ms +6.72% -1.84% 1162.21 ms +8.6% -4.67% 0.38%
loadPages 1025.79 ms +5.45% -0.95% 1017.42 ms +1.39% -2.14% 0.82%
wpTotal 516.33 ms +2.13% -6.36% 528.59 ms +4.39% -4.85% -2.32%
wpMemoryUsage 12.77 MB +0% -0% 12.73 MB +0% -0% 0.27%
wpDbQueries 44 +2.27% -0% 44 +2.27% -0% 0%

be9a263 Run

🏁 Flaky tests

Some 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.

Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 1,
+   "offset": 1,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
should select by dragging into nested block in /test/e2e/specs/editor/various/multi-block-selection.spec.js, passed after 1 failed attempt.
Error: expect(received).toEqual(expected) // deep equality

- Expected  - 1
+ Received  + 0

  Array [
    1,
-   2,
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:569:5

be9a263 Run

@ellatrix
ellatrix marked this pull request as ready for review October 30, 2026 04:06
@ellatrix
ellatrix merged commit 1ba3ff4 into trunk Oct 30, 2026
137 checks passed
@ellatrix
ellatrix deleted the claude/charming-carson-ea18d5 branch October 30, 2026 18:23
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Oct 30, 2026
Xmerlin7 added a commit to Xmerlin7/gutenberg that referenced this pull request Oct 30, 2026
Rich Text: Mark undo levels from the change handler (WordPress#86007)
@ellatrix ellatrix added the Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 24, 2026
@github-actions

Copy link
Copy Markdown

There was a conflict while trying to cherry-pick the commit to the wp/7.2 branch. Please resolve the conflict manually and create a PR to the wp/7.2 branch.

PRs to wp/7.2 are similar to PRs to trunk, but you should base your PR on the wp/7.2 branch instead of trunk.

# Checkout the wp/7.2 branch instead of trunk.
git checkout wp/7.2

# Create a new branch for your PR.
git checkout -b my-branch

# Cherry-pick the commit.
git cherry-pick 1ba3ff4c465f59d5702ab37958b73f550c854db0

# Check which files have conflicts.
git status

# Resolve the conflict...
# Add the resolved files to the staging area.
git status
git add .
git cherry-pick --continue

# Push the branch to the repository
git push origin my-branch

# Create a PR and set the base to the wp/7.2 branch.
# See https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request.

@t-hamano

Copy link
Copy Markdown
Contributor

Backported: #87426 87386

@t-hamano t-hamano added Backported to WP Core Pull request that has been successfully merged into WP Core and removed Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Nov 26, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
wporg-sync pushed a commit to WordPress/wordpress-develop that referenced this pull request Dec 1, 2026
This updates the pinned commit hash of the Gutenberg repository from `c5bdc7f4898ec98114cdccbe1cacec7a979b85cc` to `423bdf39aaa34a710acc338d3e89eac5b920fe6d` (head of the `wp/7.2` branch).

A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@c5bdc7f...423bdf3.

- Rich Text: Mark undo levels from the change handler (WordPress/gutenberg#86007) (WordPress/gutenberg#87386)
- Editor: Make plugin icons in the Options menu follow the text color (WordPress/gutenberg#87399) (WordPress/gutenberg#87405)
- Entity Fields: Track wp_entity_fields_api_init firing internally in the registry (WordPress/gutenberg#87387) (WordPress/gutenberg#87450)
- Block Editor: Count every rendered inspector group when showing the Styles tab (WordPress/gutenberg#87403) (WordPress/gutenberg#87475)
- iOS: Put the caret back when iOS clears it after a tap (WordPress/gutenberg#87569)
- Abilities: Accept non-ASCII URLs in the `uri` schema format (WordPress/gutenberg#86844)
- Writing flow: Keep shift+arrow selection inside a block edited as HTML (WordPress/gutenberg#84135)

Developed in: #16361

Props isabel_brison, ramonopoly.
See #66340.



git-svn-id: https://develop.svn.wordpress.org/trunk@65840 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Dec 1, 2026
This updates the pinned commit hash of the Gutenberg repository from `c5bdc7f4898ec98114cdccbe1cacec7a979b85cc` to `423bdf39aaa34a710acc338d3e89eac5b920fe6d` (head of the `wp/7.2` branch).

A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@c5bdc7f...423bdf3.

- Rich Text: Mark undo levels from the change handler (WordPress/gutenberg#86007) (WordPress/gutenberg#87386)
- Editor: Make plugin icons in the Options menu follow the text color (WordPress/gutenberg#87399) (WordPress/gutenberg#87405)
- Entity Fields: Track wp_entity_fields_api_init firing internally in the registry (WordPress/gutenberg#87387) (WordPress/gutenberg#87450)
- Block Editor: Count every rendered inspector group when showing the Styles tab (WordPress/gutenberg#87403) (WordPress/gutenberg#87475)
- iOS: Put the caret back when iOS clears it after a tap (WordPress/gutenberg#87569)
- Abilities: Accept non-ASCII URLs in the `uri` schema format (WordPress/gutenberg#86844)
- Writing flow: Keep shift+arrow selection inside a block edited as HTML (WordPress/gutenberg#84135)

Developed in: WordPress/wordpress-develop#16361

Props isabel_brison, ramonopoly.
See #66340.


Built from https://develop.svn.wordpress.org/trunk@65840


git-svn-id: http://core.svn.wordpress.org/trunk@64869 1a063a9b-81f0-0310-95a4-ce76da25c4cd
wporg-sync pushed a commit to WordPress/wordpress-develop that referenced this pull request Dec 1, 2026
This updates the pinned commit hash of the Gutenberg repository from `c5bdc7f4898ec98114cdccbe1cacec7a979b85cc` to `423bdf39aaa34a710acc338d3e89eac5b920fe6d` (head of the `wp/7.2` branch).

A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@c5bdc7f...423bdf3.

- Rich Text: Mark undo levels from the change handler (WordPress/gutenberg#86007) (WordPress/gutenberg#87386)
- Editor: Make plugin icons in the Options menu follow the text color (WordPress/gutenberg#87399) (WordPress/gutenberg#87405)
- Entity Fields: Track wp_entity_fields_api_init firing internally in the registry (WordPress/gutenberg#87387) (WordPress/gutenberg#87450)
- Block Editor: Count every rendered inspector group when showing the Styles tab (WordPress/gutenberg#87403) (WordPress/gutenberg#87475)
- iOS: Put the caret back when iOS clears it after a tap (WordPress/gutenberg#87569)
- Abilities: Accept non-ASCII URLs in the `uri` schema format (WordPress/gutenberg#86844)
- Writing flow: Keep shift+arrow selection inside a block edited as HTML (WordPress/gutenberg#84135)

Developed in: #16361

Reviewed by Mamaduka. Merges r65840 to the 7.2 branch.

Props peterwilsoncc, isabel_brison, ramonopoly.
See #66340.

git-svn-id: https://develop.svn.wordpress.org/branches/7.2@65843 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Dec 1, 2026
This updates the pinned commit hash of the Gutenberg repository from `c5bdc7f4898ec98114cdccbe1cacec7a979b85cc` to `423bdf39aaa34a710acc338d3e89eac5b920fe6d` (head of the `wp/7.2` branch).

A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@c5bdc7f...423bdf3.

- Rich Text: Mark undo levels from the change handler (WordPress/gutenberg#86007) (WordPress/gutenberg#87386)
- Editor: Make plugin icons in the Options menu follow the text color (WordPress/gutenberg#87399) (WordPress/gutenberg#87405)
- Entity Fields: Track wp_entity_fields_api_init firing internally in the registry (WordPress/gutenberg#87387) (WordPress/gutenberg#87450)
- Block Editor: Count every rendered inspector group when showing the Styles tab (WordPress/gutenberg#87403) (WordPress/gutenberg#87475)
- iOS: Put the caret back when iOS clears it after a tap (WordPress/gutenberg#87569)
- Abilities: Accept non-ASCII URLs in the `uri` schema format (WordPress/gutenberg#86844)
- Writing flow: Keep shift+arrow selection inside a block edited as HTML (WordPress/gutenberg#84135)

Developed in: #16361

Reviewed by Mamaduka. Merges r65840 to the 7.2 branch.

Props peterwilsoncc, isabel_brison, ramonopoly.
See #66340.
Built from https://develop.svn.wordpress.org/branches/7.2@65843


git-svn-id: http://core.svn.wordpress.org/branches/7.2@64872 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backported to WP Core Pull request that has been successfully merged into WP Core [Package] Block editor /packages/block-editor [Type] Performance Related to performance efforts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants