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

Remove any existing subscriptions before adding a new save metaboxes sub to prevent multiple saves #17522

Merged

Conversation

glendaviesnz
Copy link
Contributor

@glendaviesnz glendaviesnz commented Sep 23, 2019

Description

Currently multiple calls to setAvailableMetaBoxesPerLocation() action causes multiple AJAX requests to post.php to be made as each call initiates a new store subscription. This change removes any existing subscription before adding a new one to ensure only one sub is in play at a time.

How has this been tested?

  1. Create a new post
  2. Open Options and enable the Custom Fields advanced panel
  3. Type some content in the post
  4. Open DevTools and run this code in the Console tab:
    wp.data.dispatch( 'core/edit-post' ).setAvailableMetaBoxesPerLocation( {"side":[],"normal":[{"id":"postcustom","title":"Custom Fields"}],"advanced":[]} );
  5. Press Publish
  6. Open DevTools and look in the Network tab and make sure there is only one requests to post.php with each publish/update

Types of changes

Fixes #14759

Checklist:

  • [ X ] Only manually tested - there are no existing unit tests for the effects, and it would require a considerable amount of mocking to add any useful tests
  • [ X ] My code follows the WordPress code style.
  • [ NA ] My code follows the accessibility standards.
  • [ X ] My code has proper inline documentation.
  • [ NA ] I've included developer documentation if appropriate.

@glendaviesnz
Copy link
Contributor Author

Have just left as draft for now as want to a bit more testing of it tomorrow.

@glendaviesnz glendaviesnz marked this pull request as ready for review September 23, 2019 19:38
packages/edit-post/src/store/effects.js Outdated Show resolved Hide resolved
@youknowriad youknowriad merged commit 9b7afbf into WordPress:master Sep 30, 2019
@youknowriad youknowriad added the [Type] Bug An existing feature does not function as intended label Sep 30, 2019
@youknowriad youknowriad added this to the Gutenberg 6.6 milestone Sep 30, 2019
youknowriad pushed a commit that referenced this pull request Sep 30, 2019
youknowriad pushed a commit that referenced this pull request Sep 30, 2019
@elliotcondon
Copy link

@glendaviesnz Great work! 🥳🎉🎉🎉

You have just made a lot of ACF users very happy indeed.
Is this likely to make its way into WP 5.3 or a later version?

@glendaviesnz
Copy link
Contributor Author

You have just made a lot of ACF users very happy indeed.
Is this likely to make its way into WP 5.3 or a later version?

no worries, @elliotcondon, turned out to be a pretty easy fix. I am pretty new to contributing sorry, so not sure how the release cycle is working for WP 5.3 - @youknowriad do you know the answer to that?

@youknowriad
Copy link
Contributor

yes, this will be included in WordPress 5.3, you can check with beta2, it's already there.

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 this pull request may close these issues.

Multiple AJAX requests to save meta boxes
3 participants