Fix MutationObserver crash when editor iframe body isn't ready#849
Conversation
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
368677c to
f35684f
Compare
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 itscontentDocument) can exist before the document'sbodydoes, so on slower editor boots this threw an uncaught TypeError. Becauseobserverwas 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
editorDoc.bodyactually exists before callingobserve().observe()has succeeded, so retries stay possible.Fixes #833
Test plan