Skip to content

Editor: Use preventDefault() for the unsaved changes warning - #86506

Merged
Mamaduka merged 1 commit into
trunkfrom
fix/unsaved-changes-warning-before-unload
Nov 9, 2026
Merged

Mamaduka merged 1 commit into
trunkfrom
fix/unsaved-changes-warning-before-unload

Conversation

@Mamaduka

@Mamaduka Mamaduka commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

What?

Triggers the unsaved changes beforeunload warning with event.preventDefault() in the editor and the widgets screen, and removes the custom warning string.

Why?

Browsers stopped showing page-provided beforeunload text in 2016 and show their own message instead, so the string was never displayed but still needed translating. preventDefault() is the standard trigger now, and returnValue stays as a fallback for Chrome before 119.

Testing Instructions

  1. Open a post or page.
  2. Type in a paragraph and reload the page. The browser shows its leave-page warning.
  3. Stay on the page, save the post and reload again. No warning.
  4. With a classic theme, open Appearance > Widgets, add a block and reload. The browser shows its leave-page warning.

change-detection.spec.js and editing-widgets.spec.js pass in Chromium.

Use of AI Tools

Authored with Claude Code (Claude Opus 5.5), reviewed by the author.

🤖 Generated with Claude Code

Browsers ignore custom beforeunload text, so drop the unused string.
Keep returnValue as a fallback for Chrome before 119. Update the
trash race comment to match the current redirect location.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mamaduka Mamaduka added the [Type] Enhancement A suggestion for improvement. label Nov 9, 2026
@github-actions github-actions Bot added [Package] Editor /packages/editor [Package] Edit Widgets /packages/edit-widgets labels Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 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: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@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: -79 B (0%)

Total Size: 8.61 MB

📦 View Changed
Filename Size Change
build/scripts/edit-widgets/index.min.js 29.1 kB -36 B (-0.12%)
build/scripts/editor/index.min.js 568 kB -43 B (-0.01%)

788ca30 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric d704230 trunk % Change
timeToFirstByte 56.8 ms +3.79% -3.17% 54.2 ms +2.77% -2.95% 4.8%
largestContentfulPaint 98 ms +2.04% -6.12% 88 ms +4.55% -0% 11.36%
lcpMinusTtfb 41.95 ms +5.24% -19.9% 34.2 ms +10.67% -3.51% 22.66%
wpBeforeTemplate 29.2 ms +4.59% -1.82% 28.31 ms +1.45% -0.71% 3.14%
wpTemplate 22.66 ms +7.19% -4.81% 22.05 ms +1.04% -5.99% 2.77%
wpTotal 52.81 ms +4.32% -3.16% 50.39 ms +3.39% -2.74% 4.8%
wpMemoryUsage 7.72 MB +0% -0% 7.69 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric d704230 trunk % Change
timeToFirstByte 46.2 ms +11.47% -1.52% 45.65 ms +6.9% -1.86% 1.2%
largestContentfulPaint 100 ms +4% -0% 100 ms +0% -4% 0%
lcpMinusTtfb 54.05 ms +0.93% -2.41% 53.75 ms +1.86% -4.56% 0.56%
wpBeforeTemplate 26.75 ms +8.41% -1.23% 26.02 ms +8.34% -0.73% 2.81%
wpTemplate 16.41 ms +5.36% -1.71% 16.16 ms +3.96% -1.11% 1.55%
wpTotal 43.21 ms +11.15% -1.99% 42.5 ms +7.91% -1.36% 1.67%
wpMemoryUsage 6.41 MB +0% -0% 6.38 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric d704230 trunk % Change
mediaProcessingJpeg 398.39 ms +1.7% -0.32% 400.85 ms +0.67% -0.35% -0.61%
mediaProcessingAvif 6158.38 ms +0.41% -0.25% 6132.63 ms +0.14% -0.3% 0.42%
mediaProcessingJpegToAvif 4256.87 ms +0.19% -0.15% 4234.42 ms +0.14% -0.09% 0.53%

media-upload

Metric d704230 trunk % Change
jpegUploadProcessing 1459.6 ms +34.56% -0.99% 1465.05 ms +4.04% -0.81% -0.37%
pngUploadProcessing 178.09 ms +55.24% -3.09% 171.63 ms +3.37% -4.85% 3.76%
largeJpegUploadProcessing 1461.21 ms +32.21% -1.36% 1472.41 ms +32.56% -1.54% -0.76%
multipleImageUploadProcessing 2033.5 ms +1.95% -0.31% 2011.38 ms +4.5% -0.14% 1.1%

post-editor

Metric d704230 trunk % Change
serverResponse 257.09 ms +2.29% -9.02% 273.48 ms +5.44% -9.98% -5.99%
firstPaint 235.65 ms +33.49% -7.99% 264.67 ms +33.99% -22.93% -10.96%
domContentLoaded 542.41 ms +1.51% -0.74% 598.4 ms +0.97% -0.89% -9.36%
loaded 543.22 ms +1.5% -0.72% 599.37 ms +0.96% -0.9% -9.37%
firstContentfulPaint 317.21 ms +3.21% -0.83% 357.02 ms +0.42% -1.96% -11.15%
firstBlock 1351.52 ms +1.33% -0.54% 1496.99 ms +1.56% -0.59% -9.72%
type 13.44 ms +5.88% -8.78% 14.32 ms +9.71% -5.94% -6.15%
typeWithoutInspector 13.28 ms +6.25% -3.77% 13.51 ms +7.77% -7.92% -1.7%
typeWithTopToolbar 17.08 ms +2.69% -2.28% 17.6 ms +4.09% -11.7% -2.95%
typeContainer 6.04 ms +10.93% -2.48% 6.6 ms +4.39% -8.64% -8.48%
focus 75.99 ms +2.28% -3.18% 78.89 ms +2.12% -3.04% -3.68%
firstFocus 162.32 ms +0% -0% 167.82 ms +0% -0% -3.28%
selectAll 242.31 ms +0.69% -0.74% 234.57 ms +2.01% -0.61% 3.3%
undo 21.45 ms +3.54% -4.29% 20.8 ms +9.52% -3.27% 3.12%
listViewOpen 51.21 ms +8.08% -10.35% 49.37 ms +8.77% -6.38% 3.73%
inserterOpen 28.73 ms +8.35% -6.54% 26.88 ms +10.01% -11.38% 6.88%
inserterHover 9.02 ms +5.21% -7.54% 8.82 ms +3.74% -6.69% 2.27%
inserterSearch 6.9 ms +10.58% -5.22% 6.72 ms +4.46% -9.82% 2.68%
loadPatterns 456.36 ms +2.68% -2.15% 465 ms +5.68% -4.61% -1.86%
wpTotal 250.44 ms +2.1% -9.28% 266.24 ms +5.8% -10.07% -5.93%
wpMemoryUsage 14.77 MB +0% -0% 14.74 MB +0% -0% 0.24%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric d704230 trunk % Change
serverResponse 452 ms +5.21% -5.44% 464.24 ms +0.94% -8.23% -2.64%
firstPaint 385.39 ms +3.62% -7.75% 362.39 ms +5.78% -10.13% 6.35%
domContentLoaded 864.17 ms +3.41% -0.97% 875.1 ms +1.26% -1.47% -1.25%
loaded 865.13 ms +3.41% -0.95% 876.28 ms +1.28% -1.48% -1.27%
firstContentfulPaint 500.24 ms +2.2% -0.99% 494.77 ms +3.06% -1.86% 1.11%
firstBlock 2552.02 ms +4.42% -0.61% 2567.23 ms +0.32% -1.39% -0.59%
type 17.63 ms +8.74% -3.29% 17.72 ms +11.12% -4.63% -0.51%
navigate 107.56 ms +6.15% -1.62% 109.09 ms +11.81% -1.95% -1.4%
loadPatterns 1268.3 ms +8.29% -10.06% 1229.87 ms +9.55% -11.43% 3.12%
loadPages 991.99 ms +2.21% -1.85% 964.07 ms +5.21% -2.79% 2.9%
wpTotal 442.56 ms +5.31% -5.58% 454.77 ms +0.97% -8.4% -2.68%
wpMemoryUsage 12.79 MB +0% -0% 12.75 MB +0% -0% 0.27%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

788ca30 Run

@Mamaduka Mamaduka self-assigned this Nov 9, 2026
@Mamaduka
Mamaduka requested a review from t-hamano November 9, 2026 09:50

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@Mamaduka

Mamaduka commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

Going to merge this; failure is unrelated; trying to fix it in #86511.

@Mamaduka
Mamaduka merged commit 3d13068 into trunk Nov 9, 2026
97 of 100 checks passed
@Mamaduka
Mamaduka deleted the fix/unsaved-changes-warning-before-unload branch November 9, 2026 10:49
@github-actions github-actions Bot added this to the Gutenberg 24.5 milestone Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Edit Widgets /packages/edit-widgets [Package] Editor /packages/editor [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants