BoxControl: Fix critical error when null value is passed#65287
Merged
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. |
tyxla
approved these changes
Sep 12, 2024
Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com>
Contributor
|
Good catch! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found this while researching this comment: #64971 (comment)
What?
This PR fixes a critical error that occurs when
nullis passed to thevaluesprop of theBoxControlcomponent.The only time this error can occur in Gutenberg project is if the following conditions are met:
blockGap(settings.appearanceToolsistrueorsettings/spacing.blockGapistrue)c85e87ab95a6e370ed70e561cc7b0ee3.mp4
Browser error log
Why?
If the theme does not have a spacing preset and the block supports the axial gap, the block spacing UI will be rendered as a
BoxControlcomponent here:gutenberg/packages/block-editor/src/components/global-styles/dimensions-panel.js
Lines 619 to 628 in d329bfb
Moreover, the initial value of the block gap is
null, which is passed as the value of thevaluesprop here.gutenberg/packages/block-editor/src/components/global-styles/dimensions-panel.js
Line 625 in d329bfb
As a result, a critical error occurs in the
isValuesDefined()function whenObject.values( null ).filteris executed:gutenberg/packages/components/src/box-control/utils.ts
Lines 180 to 183 in d329bfb
How?
Perhaps the ideal solution would be to investigate why the initial value of the blockGap is
nulland convert it toundefined. However, theSpacingSizesControlcomponent also has theisValuesDefined()function, which checks fornullin addition toundefined:gutenberg/packages/block-editor/src/components/spacing-sizes-control/utils.js
Lines 238 to 243 in 0f0c68a
Therefore, it seems better to add a
nullcheck to theBoxControlcomponent itself as well.Testing Instructions
theme.jsonas follows:{ "version": 3, "settings": { "appearanceTools": true, "layout": { "contentSize": "840px" }, "spacing": { "spacingSizes": [], "defaultSpacingSizes": false } } }