You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Gutenberg 6.4 introduced the following bug:
When (meta) data is saved along a post, which is sanitized server side, the returned updated data is not available/synced in the core/editor data store as it was pre-6.4.
Steps to reproduce the buggy behavior/output
In WP 5.2.3 (with Gutenberg 6.4 or 6.5 active) register the test meta field: add_action( 'init', function() { register_post_meta( 'page', 'test_key', array( 'show_in_rest' => true, 'single' => true, 'type' => 'string', 'sanitize_callback' => 'sanitize_key', )); }); Please note the sanitize callback
Add and publish a test page
Open the console and enter: > wp.data.dispatch('core/editor').editPost({ meta: { test_key: 'TEST!!!' } })
Press the [Update] button
The post will be saved but please note that the button will stay active! ... so the document is still 'dirty'
Paste in console: > wp.data.select('core/editor').getEditedPostAttribute('meta')
The console will show: < {test_key: "TEST!!!"}
So it still shows the old data
If you have a look at the Network output you'll see that the back-end did return the expected sanitized data correctly though:
Expected behavior/output
If your repeat the same steps without Gutenberg active or with a pre-6.4 version then the
console output will be as expected showing the sanitized data: < {test_key: "test"}
the [Update] button will be greyed-out after the post has been saved.
The document is no longer dirty.
Screenshots
Console output (bugged) with Gutenberg 6.4 or 6.5:
Console output (correct) without Gutenberg or pre-6.4:
Notes:
Please also note that the pre GB 6.4 test returns 'undefined' after the dispatch while
the GB 6.5 test returns: 'Promise {: undefined}'
Maybe that is an indication where the bug originates?
This bug leads to a very bad user experience in real world situations:
withSelect(TextControl) related to the meta won't be updated with the server returned sanitized value
the editor will remain in dirty state:
the Update button will stay active, no matter how often you click it.
when the user in the end moves away from the edited page they get a warning alert about lossing unsaved data.
I don't know of any work-around.
Not sanitizing the data would be unsafe and also user unfriendly.
P.S. tested in real world situation and in simplified local test situation with blank WP 5.2.3 installation and WP 5.3beta1, with and without Gutenberg plugin active (tested with versions 6.3,6.4 and 6.5). No other plugins and Twenty Nineteen theme.
The text was updated successfully, but these errors were encountered:
bvlgn
changed the title
Sanitized meta data not available from core/editor store (since Gutenberg 6.4)
Editor stuck in dirty mode due to received sanitized data
Sep 24, 2019
Gutenberg 6.4 introduced the following bug:
When (meta) data is saved along a post, which is sanitized server side, the returned updated data is not available/synced in the core/editor data store as it was pre-6.4.
Steps to reproduce the buggy behavior/output
In WP 5.2.3 (with Gutenberg 6.4 or 6.5 active) register the test meta field:
add_action( 'init', function() { register_post_meta( 'page', 'test_key', array( 'show_in_rest' => true, 'single' => true, 'type' => 'string', 'sanitize_callback' => 'sanitize_key', )); });
Please note the sanitize callback
Add and publish a test page
Open the console and enter:
> wp.data.dispatch('core/editor').editPost({ meta: { test_key: 'TEST!!!' } })
Press the
[Update]
buttonThe post will be saved but please note that the button will stay active! ... so the document is still 'dirty'
Paste in console:
![network-response](https://webcf.waybackmachine.org/web/20240704120459im_/https://user-images.githubusercontent.com/13752843/65287012-d71efc00-db41-11e9-9412-dac1171bd0bf.png)
> wp.data.select('core/editor').getEditedPostAttribute('meta')
The console will show:
< {test_key: "TEST!!!"}
So it still shows the old data
If you have a look at the Network output you'll see that the back-end did return the expected sanitized data correctly though:
Expected behavior/output
If your repeat the same steps without Gutenberg active or with a pre-6.4 version then the
console output will be as expected showing the sanitized data:
< {test_key: "test"}
[Update]
button will be greyed-out after the post has been saved.Screenshots
![bug-console-content](https://webcf.waybackmachine.org/web/20240704120459im_/https://user-images.githubusercontent.com/13752843/65286143-c8831580-db3e-11e9-8b03-7d05597ec8c2.png)
Console output (bugged) with Gutenberg 6.4 or 6.5:
Console output (correct) without Gutenberg or pre-6.4:
![no-bug-console-content](https://webcf.waybackmachine.org/web/20240704120459im_/https://user-images.githubusercontent.com/13752843/65286101-abe6dd80-db3e-11e9-9c62-dc3eb2af6dd9.png)
Notes:
Please also note that the pre GB 6.4 test returns 'undefined' after the dispatch while
the GB 6.5 test returns: 'Promise {: undefined}'
Maybe that is an indication where the bug originates?
This bug leads to a very bad user experience in real world situations:
I don't know of any work-around.
Not sanitizing the data would be unsafe and also user unfriendly.
P.S. tested in real world situation and in simplified local test situation with blank WP 5.2.3 installation and WP 5.3beta1, with and without Gutenberg plugin active (tested with versions 6.3,6.4 and 6.5). No other plugins and Twenty Nineteen theme.
The text was updated successfully, but these errors were encountered: