Image block: Add guard for null refs in setButtonStyles callback#72715
Image block: Add guard for null refs in setButtonStyles callback#72715luisherranz merged 1 commit intotrunkfrom
null refs in setButtonStyles callback#72715Conversation
|
Size Change: +14 B (0%) Total Size: 2.37 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in b302e84. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18846636838
|
|
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. |
Co-authored-by: DAreRodz <[email protected]> Co-authored-by: luisherranz <[email protected]>
|
I just cherry-picked this PR to the wp/6.9 branch to get it included in the next release: 612afc3 |
What?
Fixes a bug in Image blocks with the "expand on click" option enabled. The bug appears when an interactive image is removed from the DOM, e.g., when you navigate in a Query block with the "Reload full page" option disabled, and the
setButtonStylescallback is triggered because of aloadevent.Why?
The error is visible in production. Also, now that the Content block is enabled inside a Query block with the "Reload full page" option disabled, this case is likely to happen.
How?
The bug fix checks if
refexists when calling thesetButtonStylescallback. We need to do so because Preact doesn't removeloadevent listeners on images by default (see preactjs/preact#3141), and theloadevent could be dispatched multiple times for the same element if it has asrcsetattribute.The ideal way to solve this would be to handle this specific case inside the
data-wp-ondirective. However, this would require agreeing on the desired behavior first, as it would mean changing Preact's default behavior.Testing Instructions