-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix inner block block crash when rendering Template Part "Replace" UI during click-through #59988
Conversation
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. |
|
Size Change: 0 B Total Size: 1.71 MB ℹ️ View Unchanged
|
What?
Fixes a block crash in the Template Part blocks that can be "Replaced".
by accounting for possible
null
value ofdocument.defaultView
when cleaning up event listeners.Why?
To avoid block crash when "clicking-through" these blocks to inner blocks that are commonly inside them.
How?
Some Template Parts are "replaceable" with other patterns. Users are shown a list of possible pattern options under the
Replace
panel in the block sidebar.These patterns use the
BlockPreview
component. Ultimately this ends up in theIframe
component.gutenberg/packages/block-editor/src/components/iframe/index.js
Line 103 in dbfed70
Each iframe has it's own
document.defaultView
which according to MDN...Currently we have event listener cleanup that always expects
defaultView
not to benull
. Unfortunately when "clicking through" the Template Part, it seems that the previews get briefly rendered and then quickly removed when the user ends up selecting an inner block of the template part.From testing, I can see that it is possible for
defaultView
to benull
and thus attemptingremoveEventListener
on it will throw an error.This PR fixes that by conditionalising the
removeEventListener
here...gutenberg/packages/block-editor/src/components/iframe/index.js
Lines 218 to 221 in dbfed70
Testing Instructions
On Trunk
Header
Template Part to do this.On this PR
Header
Template Part to do this.Testing Instructions for Keyboard
Screenshots or screencast
Before (On Trunk)
Screen.Capture.on.2024-03-19.at.11-00-50.mp4
After (this PR)
Screen.Capture.on.2024-03-19.at.11-01-40.mp4