Gutenberg: Two checkbox controls in PluginPostStatusInfo – clicking one triggers both

Created on 25 Nov 2018  Â·  4Comments  Â·  Source: WordPress/gutenberg

Describe the bug

I have two plugin installed, that both add a checkbox to the publish area via PluginPostStatusInfo. If one of both is already clicked and I reload the editor, both get triggered if I click the box that is not checked. If both are checked, both get unchecked. After the first click, it works.

But the changed status of the not-clicked checkbox does not get saved – after clicking update, the correct status gets highlighted again.

To Reproduce

Steps to reproduce the behavior:

Not so easy, the checkbox values are depending on custom meta values.

I created a Gist with the code of both checkboxes in one file, so you can take a look how the code is: https://gist.github.com/florianbrinkmann/2c1fd1b7477f28354d65380dcc8c4170

Expected behavior
Only the one checkbox should be triggered.

Screenshots

two-checkbox-issue

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Firefox
  • Version: 65.0a1 (2018-11-24) (64-Bit)

Additional context

  • Gutenberg 4.5.1.
[Type] Bug

All 4 comments

According to the comment on #10827, that PR might be related to this behavior.

In a plugin of mine that hooks into PluginPostStatusInfo I also use editPost in the onChange callback, but I merge old and new meta data there so this does not happen.

See https://github.com/swissspidy/video-post-type/blob/0942bc7d6dc08ac1f5841032dbed295cd74a6670/assets/js/src/components/video-panel/index.js#L43-L63 for an example.

Could you try that in your plugin as well and let us know if it works? :-)

I merge old and new meta data there so this does not happen.

Yes, this should solve the issue and this is how we were supposed to do it before #10827 anyway. So It's not really a regression but with #10827, in theory we should be able to apply partial changes, which means if we update the getEditedPostAttribute selector to "merge" automatically edited metas with non-edited ones, the code here will just work.

Thanks @swissspidy, that works! Honestly, I don’t exactly understand why, but will try to dive into that topic later :)

While @swissspidy's workaround may be effective, I'd still consider this to be a bug in how we fail to merge meta properties with edited values from the getEditedPostAttribute selector. A developer shouldn't need to pass all meta properties through to editPost if they're not in-fact intending to edit all meta properties.

Was this page helpful?
0 / 5 - 0 ratings