Skip to content

Try: Detect fields outside the editor history instead of registering them with useNativeUndo - #87138

Draft
t-hamano wants to merge 5 commits into
trunkfrom
try/auto-detect-native-undo
Draft

t-hamano wants to merge 5 commits into
trunkfrom
try/auto-detect-native-undo

Conversation

@t-hamano

@t-hamano t-hamano commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What?

See #18755. Follow up to #80768.

Proof of concept: replace the opt-in useNativeUndo registry with automatic detection, so every text field whose text is not part of the editor history leaves Cmd+Z / Cmd+Shift+Z to the browser, without per-component registration.

If this approach looks feasible, I'll add end-to-end tests.

Why?

Only fields registered through useNativeUndo keep the browser's own undo. Many other local-state fields still have undo taken over by the editor history, which rewinds an unrelated change. Registering each of them does not scale.

How?

After a keystroke changes a text field's value, check whether the editor history (getReferenceByDistinctEdits) changed too. If not, the field is treated as local and undo is left to the browser. useNativeUndo and its four usages are removed.

Testing Instructions

  1. Open a post and type in a paragraph.
  2. Open the block rename modal on a Group block, type, press Cmd+Z: the typing reverts, the paragraph is untouched.
  3. Type in the inserter search, press Cmd+Z: the search text reverts, the paragraph is untouched.
  4. Type in Advanced > HTML anchor, press Cmd+Z: the editor history undoes it, as on trunk.

Use of AI Tools

Investigation, implementation and this description were written with Claude Code.

…ng them

Replace the `useNativeUndo` registry with automatic detection. A keystroke
that changes a text field's value without changing the editor history means
the field keeps its text locally, so undo and redo there are left to the
browser. Fields whose typing edits the history keep the editor undo.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URwSqkS4bYhMhnseFgi
@t-hamano t-hamano self-assigned this Nov 20, 2026
@github-actions github-actions Bot added [Package] Editor /packages/editor [Package] Block library /packages/block-library [Package] Block editor /packages/block-editor [Package] Edit Post /packages/edit-post [Package] Edit Widgets /packages/edit-widgets labels Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

📦 Bundle size

Size Change: +284 B (0%)

Total Size: 8.68 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 557 kB +216 B (+0.04%)
build/scripts/block-library/index.min.js 427 kB -17 B (0%)
build/scripts/customize-widgets/index.min.js 22.9 kB +38 B (+0.17%)
build/scripts/edit-post/index.min.js 45.2 kB -32 B (-0.07%)
build/scripts/edit-widgets/index.min.js 29.2 kB +41 B (+0.14%)
build/scripts/editor/index.min.js 572 kB +38 B (+0.01%)

67b453d Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 3c3d36f trunk % Change
timeToFirstByte 43.45 ms +11.28% -3.45% 44.3 ms +7.9% -4.29% -1.92%
largestContentfulPaint 72 ms +5.56% -5.56% 68 ms +5.88% -5.88% 5.88%
lcpMinusTtfb 25.65 ms +10.14% -9.36% 23.25 ms +15.05% -6.88% 10.32%
wpBeforeTemplate 22.73 ms +2.33% -2.86% 22.73 ms +3.43% -1.94% 0%
wpTemplate 17.63 ms +3.35% -5.73% 17.64 ms +2.49% -4.37% -0.06%
wpTotal 40.07 ms +10.71% -3.52% 40.44 ms +10.09% -3.17% -0.91%
wpMemoryUsage 7.75 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 3c3d36f trunk % Change
timeToFirstByte 37.5 ms +6.4% -6% 35.15 ms +13.09% -0.85% 6.69%
largestContentfulPaint 68 ms +5.88% -5.88% 64 ms +6.25% -0% 6.25%
lcpMinusTtfb 29.55 ms +7.45% -2.71% 28.85 ms +1.21% -6.07% 2.43%
wpBeforeTemplate 20.09 ms +11.85% -4.58% 19.42 ms +14.78% -1.29% 3.45%
wpTemplate 13.42 ms +6.26% -4.47% 13.11 ms +2.44% -2.44% 2.36%
wpTotal 34.78 ms +5.81% -6.67% 32.47 ms +10.72% -1.2% 7.11%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 3c3d36f trunk % Change
mediaProcessingJpeg 323.63 ms +0.53% -0.34% 325.58 ms +1.44% -1.09% -0.6%
mediaProcessingAvif 4860.19 ms +0.14% -0.63% 4843.28 ms +0.55% -0.14% 0.35%
mediaProcessingJpegToAvif 3394.3 ms +0.39% -0.24% 3396.54 ms +0.62% -0.58% -0.07%

media-upload

Metric 3c3d36f trunk % Change
jpegUploadProcessing 1468.21 ms +1.24% -0.95% 1449.01 ms +1.05% -0.34% 1.33%
pngUploadProcessing 243.9 ms +2.23% -8.27% 243.5 ms +14.83% -6.3% 0.16%
largeJpegUploadProcessing 1438.51 ms +0.65% -0.82% 1438.67 ms +0.4% -0.46% -0.01%
multipleImageUploadProcessing 1502.76 ms +1.59% -0.37% 1502.46 ms +1.09% -0.38% 0.02%

post-editor

Metric 3c3d36f trunk % Change
serverResponse 269.27 ms +4.3% -5.53% 270.49 ms +8.58% -5.41% -0.45%
firstPaint 296.78 ms +3.61% -11.64% 281.54 ms +4.37% -7.06% 5.41%
domContentLoaded 531.49 ms +2.7% -0.62% 576.34 ms +0.84% -3.43% -7.78%
loaded 532.21 ms +2.72% -0.62% 577.28 ms +0.82% -3.44% -7.81%
firstContentfulPaint 306.6 ms +3.45% -2.66% 319.9 ms +4.2% -1.36% -4.16%
firstBlock 1432.01 ms +2.01% -2.12% 1486.79 ms +2.83% -0.34% -3.68%
type 13.57 ms +7.3% -11.57% 14 ms +9.36% -9.57% -3.07%
typeWithoutInspector 13.56 ms +5.68% -12.39% 14.3 ms +11.26% -10.28% -5.17%
typeWithTopToolbar 16.34 ms +12.73% -7.34% 17.58 ms +3.75% -9.95% -7.05%
typeContainer 6.45 ms +4.03% -14.26% 6.3 ms +5.87% -7.78% 2.38%
focus 77.88 ms +3.61% -5.74% 90.52 ms +3.16% -6.66% -13.96%
firstFocus 178.48 ms +0% -0% 201.04 ms +0% -0% -11.22%
selectAll 259.56 ms +1.13% -1.78% 254.59 ms +5.03% -2.82% 1.95%
undo 22.45 ms +4.68% -4.1% 23.89 ms +9.59% -2.64% -6.03%
listViewOpen 52.04 ms +1.33% -3.31% 48.44 ms +6.52% -8.61% 7.43%
inserterOpen 28.53 ms +16.96% -3.72% 28.45 ms +13.71% -4.92% 0.28%
inserterHover 9.47 ms +5.49% -7.07% 8.83 ms +8.38% -3.06% 7.25%
inserterSearch 7.45 ms +2.15% -11.41% 6.7 ms +8.21% -3.28% 11.19%
loadPatterns 465.04 ms +1.54% -3.05% 439.39 ms +2.31% -2.4% 5.84%
wpTotal 262.28 ms +4.14% -6.77% 263.49 ms +8.3% -5.57% -0.46%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 3c3d36f trunk % Change
serverResponse 480.42 ms +0.53% -6.85% 461.99 ms +0.57% -7.86% 3.99%
firstPaint 436 ms +6.8% -5.59% 454.81 ms +1.35% -14.87% -4.14%
domContentLoaded 850.8 ms +1.38% -1.57% 820.96 ms +1.34% -0.86% 3.63%
loaded 851.75 ms +1.44% -1.55% 821.86 ms +1.34% -0.83% 3.64%
firstContentfulPaint 475.53 ms +6.24% -2.08% 456.86 ms +1.37% -0.55% 4.09%
firstBlock 2600.23 ms +0.92% -2.11% 2528.07 ms +0.67% -0.48% 2.85%
type 17.37 ms +6.74% -6.62% 16.11 ms +7.2% -3.91% 7.82%
navigate 111.09 ms +3.96% -1.21% 111.52 ms +1.92% -3.83% -0.39%
loadPatterns 1352.73 ms +12.79% -4.41% 1239.35 ms +5.24% -17.6% 9.15%
loadPages 965.59 ms +3.32% -1.6% 935.84 ms +1.52% -1.48% 3.18%
wpTotal 470.32 ms +0.67% -6.85% 452.61 ms +0.57% -8.1% 3.91%
wpMemoryUsage 12.83 MB +0% -0% 12.80 MB +0% -0% 0.25%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

67b453d 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.

As a user I want to be able to add multiple close buttons so that users can close the overlay from different positions in /test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js, passed after 1 failed attempt.
Error: expect(locator).toHaveCount(expected) failed

Locator:  getByRole('button', { name: 'Close' })
Expected: 2
Received: 1
Timeout:  5000ms

Call log:
  - Expect "toHaveCount" getByRole('button', { name: 'Close' }) with timeout 5000ms
  - waiting for getByRole('button', { name: 'Close' })
    14 × locator resolved to 1 element
       - unexpected value "1"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js:228:33
should select synced pattern in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]') with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
    14 × locator resolved to <div tabindex="0" role="document" draggable="true" data-title="Pattern" data-type="core/block" data-is-drop-zone="true" aria-label="Block: Pattern" id="block-226bd219-db72-456c-810e-31af7570d172" data-block="226bd219-db72-456c-810e-31af7570d172" class="block-editor-block-list__block wp-block is-selected is-reusable block-library-block__reusable-block-container wp-block-block block-editor-block-list__layout">…</div>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:1464:5

67b453d Run

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended and removed [Package] Editor /packages/editor [Package] Block library /packages/block-library [Package] Block editor /packages/block-editor [Package] Edit Post /packages/edit-post [Package] Edit Widgets /packages/edit-widgets labels Nov 20, 2026
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URwSqkS4bYhMhnseFgi
@github-actions github-actions Bot added [Package] Editor /packages/editor [Package] Block library /packages/block-library [Package] Block editor /packages/block-editor [Package] Edit Post /packages/edit-post [Package] Edit Widgets /packages/edit-widgets labels Nov 20, 2026
claude and others added 3 commits November 20, 2026 09:16
…field

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URwSqkS4bYhMhnseFgi
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URwSqkS4bYhMhnseFgi
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URwSqkS4bYhMhnseFgi

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Package] Block library /packages/block-library [Package] Edit Post /packages/edit-post [Package] Edit Widgets /packages/edit-widgets [Package] Editor /packages/editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants