-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Global styles: Fix error when updating padding input in global styles #49465
Conversation
Size Change: +6 B (0%) Total Size: 1.34 MB
ℹ️ View Unchanged
|
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, this fixes the issue!
I think the problem is that we we're not checking whether value
exists before calling cloneObject
with it on line 35. I guess we could have checked value instead, but it seems more foolproof to check if the object exists before recursing on it.
@@ -27,7 +27,7 @@ function normalizePath( path ) { | |||
* @return {*} Cloned object, or original literal non-object value. | |||
*/ | |||
function cloneObject( object ) { | |||
if ( typeof object === 'object' ) { | |||
if ( object && typeof object === 'object' ) { |
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.
Is there a test case that can be added to the tests for immutableSet
?
BTW, cloneObject
wasn't introduced in #49365, it was already in the codebase. I think it might be from the refactor away from lodash, so it might be good to check what lodash does in this situation and mirror that.
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.
It looks like this is what happens:
_.set( null, [ 'path' ], 'value' ); // returns `null`
_.set( undefined, [ 'path' ], 'value' ); // returns `undefined`
So I think the fix is good in that it still returns the original value.
Ignore this, the bug is different, and immutableSet
does work differently to lodash set
.
I've added some tests that catch the issue, which was specifically happening when using immutableSet
on objects that have a nested null
property. (that was mentioned in the PR description, but I read it too quickly 😄 )
Flaky tests detected in 1a253a2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4561612597
|
Adding @tyxla here as I believe he originally wrote this utility. He might have better insights. |
Merging for now so that the bug is solved. The specific implementation can always be revisited. |
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.
typeof null
will be object
, so this will do the job to prevent this, thanks 👍
Thanks for merging and the discussion, and for adding in the tests @talldan! 🙇 |
Folks, we the Theme Designers from Dotorg are still getting this error for a couple of days now. I was about to create a PR when @mtias pointed me to this one. Are you still on it? |
@henriqueiamarino, which version of Gutenberg are you running? I've just retested adjusting padding in global styles in If you're still able to replicate the issue on trunk, do you mind sharing the error message? (Either copy/paste from the console, or via the Copy Error button). |
…#49465) * Fix padding input in global styles * Add tests --------- Co-authored-by: Daniel Richards <[email protected]>
Is it possible this PR introduced a bug where all global settings are saved in global styles when updating the site layout? Please see here: #53868 |
What?
Fix an error being thrown when going to update padding values at the root level in global styles.
Why?
A
cloneObject
utility function was added in #49365. It looks like it gets called when updating the padding values in global styles, with anull
value. Anull
value in this function results in thetypeof
check being truthy becausenull
is an object. This then throws an error.In this case it looks like
cloneObject
gets called recursively, where it's possible for it be called with anull
value, so we need an additional truthy check, as the one inimmutableSet
isn't quite enough. Thanks @tellthemachines for spotting that!How?
Add a truthy check to the
cloneObject
function so thatnull
doesn't cause the code to be executed.Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
This is the error state that occurred: