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

Unrelated meta data gets saved with default value #6505

Closed
2 tasks
ocean90 opened this issue Apr 30, 2018 · 4 comments
Closed
2 tasks

Unrelated meta data gets saved with default value #6505

ocean90 opened this issue Apr 30, 2018 · 4 comments
Assignees
Labels
[Feature] Blocks Overall functionality of blocks REST API Interaction Related to REST API [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@ocean90
Copy link
Member

ocean90 commented Apr 30, 2018

Issue Overview

If you have a block which stores its data in post meta and also registered other post meta for REST API usage, the other post meta gets also updated with the default value.

Steps to Reproduce (for bugs)

  1. Example plugin: https://gist.github.com/ocean90/7431114b689f1e0686f4f5dfa88838df
  2. Activate plugin
  3. Add the new block and fill the input
  4. Save draft and inspect the save request
  5. Notice that the meta entry includes all three meta keys while only one has been changed

Expected Behavior

Only changed meta data should get saved.

Possible Solution

I'm not sure yet if that's a limitation of the REST API and/or if Gutenberg can enhance that behaviour.

Related Issues

Todos

  • Tests
  • Documentation
@ocean90 ocean90 added [Type] Bug An existing feature does not function as intended [Feature] Blocks Overall functionality of blocks labels Apr 30, 2018
@jorgefilipecosta
Copy link
Member

jorgefilipecosta commented May 2, 2018

Hi @ocean90,
Thank you for reporting this issue, I'm able to replicate it in my tests.
It looks like it is a rest API bug.

The rest API returns all the meta fields (available in rest) even if they have no data, which I guess is ok.
If there no changes in metadata (all fields are empty) so Gutenberg sends in the save request the same metadata it received (all fields with an empty string). In this case, the rest API correctly ignores all metadata and does not save it to the database.

If we change one field (for example using the block @ocean90 provided), Gutenberg save request contains all non-changed fields precisely as they were provided (with an empty string), and in the changed field, we set the new value. In this case, the rest API instead of ignoring all non-changed empty fields and just saving the non empty one to the database it saves both the empty fields and the new value.

@jorgefilipecosta jorgefilipecosta added [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked. Core REST API Task Task for Core REST API efforts labels May 2, 2018
@ocean90
Copy link
Member Author

ocean90 commented May 15, 2018

I don't think that this is a REST API bug but rather that Gutenberg should only send changed meta values back to the REST API.

@felixarntz
Copy link
Member

I agree with @ocean90 in that matter. I think Gutenberg should check if the meta value is different from the initial value retrieved from the API before it passes it there.

@danielbachhuber danielbachhuber added this to the WordPress 5.0 milestone Jun 4, 2018
@earnjam earnjam self-assigned this Aug 14, 2018
@danielbachhuber danielbachhuber added REST API Interaction Related to REST API and removed REST API Interaction Related to REST API labels Oct 8, 2018
@earnjam earnjam removed Core REST API Task Task for Core REST API efforts [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked. labels Oct 20, 2018
@mtias mtias added the [Status] In Progress Tracking issues with work in progress label Nov 15, 2018
@aduth
Copy link
Member

aduth commented Nov 19, 2018

Closed by #10827.

@aduth aduth closed this as completed Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks REST API Interaction Related to REST API [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

7 participants