Skip to content
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

Editor stuck in dirty mode due to received sanitized data #17491

Closed
bvlgn opened this issue Sep 19, 2019 · 1 comment · Fixed by #17532
Closed

Editor stuck in dirty mode due to received sanitized data #17491

bvlgn opened this issue Sep 19, 2019 · 1 comment · Fixed by #17532
Labels
[Type] Bug An existing feature does not function as intended

Comments

@bvlgn
Copy link

bvlgn commented Sep 19, 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

  1. 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

  2. Add and publish a test page

  3. Open the console and enter:
    > wp.data.dispatch('core/editor').editPost({ meta: { test_key: 'TEST!!!' } })

  4. Press the [Update] button
    The post will be saved but please note that the button will stay active! ... so the document is still 'dirty'

  5. 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:
    network-response

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:
bug-console-content

Console output (correct) without Gutenberg or pre-6.4:
no-bug-console-content

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.

@bvlgn 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
@youknowriad
Copy link
Contributor

Thanks Benny for opening that issue. we're working on it on this PR which will solve the issue #17532

@youknowriad youknowriad added the [Type] Bug An existing feature does not function as intended label Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants