-
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
Legacy Widget add support for widgets with attributes that can't be serialised into JSON #28902
Comments
The Customizer addresses this by using base64 encoded strings instead of JSON to send a widget's attributes to the frontend. I think we should take a similar approach in the Legacy Widget block. |
Here's roughly how I think the Legacy Widget block can work. An empty Legacy Widget block contains just an ID.
After it is mounted, the block makes a request to
The HTML in After the user makes some edits in the Edit tab, the block grabs the form data and
The Edit tab is then replaced with the updated HTML in
When the block again wants to render the Edit tab in the future, it provides the encoded instance.
Finally, to render the Preview tab, the block provides the encoded instance to the iframe.
Things to note:
|
This seems sensible to me. We need to make sure we apply the same hashing that the customizer does to avoid unserializing arbitrary input. |
The repro steps posted in the description now work but you can still see an error to do with incorrect serialisation if you click Preview on the Legacy Widget. |
Noting that need to remove the temporary hack added in #29365 as part of fixing this. |
I've opened #29649 which contains the REST API changes needed for this.
edit: Did not end up doing this deviation. See #29649 (comment) 🙂 |
I've opened #29960 which is a WIP PR containing the frontend changes needed for this. |
Description
The Legacy Widget block will choke when used with a widget that has an instance attribute which can't be serialised into JSON. WordPress supports storing any PHP value in a widget's instance attributes.
Step-by-step reproduction instructions
gutenberg.php
:Navigate to Appearance → Widgets.
Use the insert to add a Date legacy widget.
Set a date and press Update.
Refresh the page.
Expected behaviour
The Date legacy widget should be in the editor and display the date that was set.
Actual behaviour
The Date legacy widget is missing from the editor and there are network errors in DevTools.
Screenshots or screen recording (optional)
WordPress information
trunk
master
The text was updated successfully, but these errors were encountered: