Skip to content

Fix MutationObserver crash when editor iframe body isn't ready#849

Merged
dkotter merged 1 commit into
WordPress:developfrom
vedant-ere:fix/833-title-generation-observer-body-null-race
Jul 9, 2026
Merged

Fix MutationObserver crash when editor iframe body isn't ready#849
dkotter merged 1 commit into
WordPress:developfrom
vedant-ere:fix/833-title-generation-observer-body-null-race

Conversation

@vedant-ere

@vedant-ere vedant-ere commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

The title toolbar's MutationObserver setup waited a fixed 500ms before assuming the editor canvas iframe was ready, then called observer.observe(editorDoc.body, ...). The iframe element (and its contentDocument) can exist before the document's body does, so on slower editor boots this threw an uncaught TypeError. Because observer was assigned before the throwing call, the setup never ran again, which also silently broke the toolbar re-attach behavior from #694 for that session.

Fix

  • Check that editorDoc.body actually exists before calling observe().
  • If it's not ready yet, retry every 200ms (capped at 20 tries) instead of relying on one fixed delay.
  • Only assign the observer once observe() has succeeded, so retries stay possible.
  • Clean up the retry timer on unmount.

Fixes #833

Test plan

Open WordPress Playground Preview

@vedant-ere vedant-ere requested a review from a team July 9, 2026 12:33
Don't assume the editor canvas iframe body exists after a fixed 500ms
delay. Retry until it's actually available, and only keep the observer
if observe() succeeds, so it doesn't get stuck non-functional.

Fixes WordPress#833
@vedant-ere vedant-ere force-pushed the fix/833-title-generation-observer-body-null-race branch from 368677c to f35684f Compare July 9, 2026 12:42
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

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: vedant-ere <vedantere@git.wordpress.org>
Co-authored-by: soydiloreto <pablodiloreto@git.wordpress.org>

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

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.74%. Comparing base (cf0cb09) to head (f35684f).

Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #849   +/-   ##
==========================================
  Coverage      75.74%   75.74%           
  Complexity      2088     2088           
==========================================
  Files             99       99           
  Lines           8630     8630           
==========================================
  Hits            6537     6537           
  Misses          2093     2093           
Flag Coverage Δ
unit 75.74% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dkotter dkotter added this to the 1.2.0 milestone Jul 9, 2026
@dkotter dkotter merged commit cf1bf71 into WordPress:develop Jul 9, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants