-
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
[customize-widgets/utils/widgetToBlock
] Initialize a widget's raw_content.content
to an empty string if it's undefined
#46487
[customize-widgets/utils/widgetToBlock
] Initialize a widget's raw_content.content
to an empty string if it's undefined
#46487
Conversation
b98176d
to
e8d4587
Compare
Size Change: +21 B (0%) Total Size: 1.32 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.
This approval means "I don't have any further comment or see anything obviously wrong with this."
I'd still recommend finding someone more familiar with the widgets who might be able to speak to why the content
was undefined.
If nobody speaks though, maybe we add a comment saying something like It's unclear why this is sometimes undefined, but it shouldn't be.
and then merge.
2b94966
to
eaa9170
Compare
…content.content` to an empty string if it's `undefined` (#46487) * Initialize a widget's raw_content.content to an empty string if it's undefined * Do not mutate the instance object's raw_instance property * Add comment
The attributes within |
@noisysocks Thanks for clarifying! I had no idea bout that. I'll give it another go following your suggestion; how do I check it's a block widget? |
Wrote too fast, sorry. I now see you came up with a proper fix in #46600. Thanks! |
…'s `raw_content.content` to an empty string if it's `undefined`" (#46600) * Revert "[`customize-widgets/utils/widgetToBlock`] Initialize a widget's `raw_content.content` to an empty string if it's `undefined` (#46487)" This reverts commit 271f650. * Guard against undefined content closer to parse() call
What?
Follow-up to #46475.
We experienced widgets with
raw_content
={}
, hence it doesn't contain a validcontent
property. This feeds invalid (undefined
) data to the parser and makes it break when it gets to https://github.com/WordPress/gutenberg/blob/trunk/packages/block-serialization-default-parser/src/index.js#L441, with:TypeError: Cannot read properties of undefined (reading 'length')
.The exception bubbles up and breaks the widget block editor:
After chatting with @dmsnell and with his help (thanks!), we continued troubleshooting the issue, and eventually decided to move the fix up the stack to this function as the root issue is not in the parser. We're still unsure where the actual culprit is as it's been hard to troubleshoot, but a guard in
widgetToBlock
seems more viable and safer than modifying the lower-level parser. If anyone has any ideas on where the culprit might be, feel free to comment here.Why?
I've experienced a crash in the customize widgets block editor because the widget JSON object's
raw
property has a value of{}
(empty object). Here's a sample widget object JSON that ended up causing the issue: https://gist.github.com/fullofcaffeine/3807914297e3e836866edf6e49b61963. Notice how theraw
property is{}
. We have no idea how it got to this state, and that's why we decided to add the guard in thewidgetToBlock
instead.How?
Add a simple guard that checks if the
raw_content
property for the given widget passed over towidgetToBlock
has anundefined
content
property, if so, we set itscontent
property to''
(empty string).Testing Instructions
I have no idea how the widget got to the state where
raw
is{}
, but you can manually change one of your widgets in your db and set theraw
property to{}
in order to reproduce it.Testing Instructions for Keyboard
Screenshots or screencast