-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
SpacerControls: Set height to empty string if undefined and add deprecations for undefined height #68819
base: trunk
Are you sure you want to change the base?
SpacerControls: Set height to empty string if undefined and add deprecations for undefined height #68819
Conversation
0px
when no value is provided
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. |
Hi @Mamaduka, could you please review this PR and share your thoughts on the proposed approach? I'd appreciate your feedback! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea to avoid setting height to undefined
seems right to me. 0px
seems a fine fallback and fixes the issue. Though perhaps an empty string is a hair better because height
will not be output in the inline styles. That said, clearing the spacer height and saving it is rare usage so not much of a concern 🤷.
Hi @stokesman, thanks for the review. I've updated the PR to include the suggested changes. The empty string works better and the styles aren't reflected in the inline styles. Thanks for pointing that out. |
Hi @carolinan, can I please get a review on this PR? |
@yogeshbhutkar, my suggestion would be to avoid pinging people often. Everyone is monitoring the PRs, and they'll get reviewed when folks have time. |
c7b6d47
to
2a44603
Compare
This solves the problem for newly inserted spacer blocks. |
return { | ||
...attributes, | ||
width: width !== undefined ? `${ width }px` : undefined, | ||
height: `${ height }px`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review!
The issue with the previously broken spacer blocks, which had missing heights, has been resolved using deprecation. The current implementation has been updated accordingly.
Additionally, the undefined check for the height attribute was redundant since a default value is always provided. Therefore, this check has been removed.
I am confused, why was the change to controls.js reverted? |
That change would then become redundant. The idea is that if undefined gets stored, the deprecation would run and initialize height to be an empty string. This way, the block validation error never occurs, and we don't need to repeat the logic twice. Therefore, that change was not required. What do you think about the approach? Should we also keep the change in control.js? |
I don't think the deprecation script should run unless it is strictly necessary, when the block is invalid. It would be better to prevent it from being invalid in the first place. |
1d10e3d
to
378a1da
Compare
0px
when no value is provided
Thanks for highlighting that! After reviewing the context, I completely agree and have incorporated the changes in my latest commit ✨. |
What, Why and How?
Fixes: #68817
When the height of the
spacer block
is set toundefined
, on reloading the editor, aRecovery Error
is shown for theSpacer Block
.The root cause of the problem lies in the fact that the default value of
height
attribute defined inblock.json
is100px
, therefore, whenever theheight
attribute is madeundefined
, on reload, the default value kicks in and causes a mismatch in the content generated by thesave
function as well as thepost body
leading to this warning:There are two potential solutions for this problem:
Remove the default value of height attribute (
100px
) fromblock.json
.gutenberg/packages/block-library/src/spacer/block.json
Line 12 in a60dd78
Save
0px
if height isundefined
.The later approach i.e. (2) makes more sense as:
i. This is how the height slider implements it.
ii. Width follows a similar approach.
iii. It doesn't quite make sense to save the height of the
spacer
asundefined
.Testing Instructions
undefined
by trying to save an empty input.Block Recovery
error occurs.Screencast
Screen.Recording.2025-01-22.at.11.23.20.AM.mov