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

Fix: consecutive updates may trigger a blocks reset #18219

Merged

Conversation

jorgefilipecosta
Copy link
Member

Description

Fixes: #18169

We had a bug in our editor provider. We subscribed to the store and saved the blocks when they changed in isSyncingOutcomingValue. When the value of the component changed, and it was not equal to the value we saved in isSyncingOutcomingValue we assumed it was an external update happening, and we triggered a block reset.
This mechanism had a problem when the updates were fast. The subscribe may execute multiple times, and setting isSyncingOutcomingValue to something more recent before componentDidUpdate executed.
When componentDidUpdate executed, the isSyncingOutcomingValue was different (more recent) than the value prop componentDidUpdate received, so we assumed there was an external update happening and triggered a block reset.
It is possible to verify that by logging calls to the resetBlock action, the action is called on Cover Block, Media & Text, and Navigation Block. These blocks use InnerBlocks with templates, and during the block setup, there are multiple updates.
The reset to a previous value was responsible for causing bug #18169.

In this PR, we make isSyncingOutcomingValue an array, and on componentDidUpdate, we compare the value against the values the array contains.

This PR should improve the performance of blocks that use templates because we avoid unnecessary resetBlocks action.

How has this been tested?

I verified I could add multiple navigation blocks, and all of them contain the top-level pages as menu items.
I added logs in resetBlocks action, and I verified when I add Media & Text, cover block (after choosing a background), and navigation block the reset blocks action was not called.

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended Framework Issues related to broader framework topics, especially as it relates to javascript [Package] Block editor /packages/block-editor labels Oct 31, 2019
Copy link
Contributor

@draganescu draganescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! This fixed the problem, tested with various scenarios and it's all O.K.

@draganescu draganescu merged commit 9529670 into master Oct 31, 2019
@draganescu draganescu deleted the fix/consecutive-updates-may-trigger-a-blocks-reset branch October 31, 2019 17:16
daniloercoli added a commit that referenced this pull request Nov 5, 2019
…rnmobile/gb-mobile-872-JSApplicationIllegalArgumentException-in-RCTAztecView

* 'master' of https://github.com/WordPress/gutenberg: (56 commits)
  Update: Default gradients. (#18214)
  Fix: setting a preset color on pullquote default style makes the block invalid (#18194)
  Fix default featured image size (#15844)
  Fix postmeta radio regression. (#18183)
  Components: Switch screen-reader-text to VisuallyHidden (#18165)
  [rnmobile] Release 1.16.0 to master (#18261)
  Template Loader: Add theme block template resolution. (#18247)
  Add a README file for storybook directory (#18245)
  Add editor-gradient-presets to get_theme_support (#17841)
  Add "Image Title Attribute" as an editable attribute on the image block (#11070)
  enables horizontal movers in social blocks (#18234)
  [RNMobile] Add mobile Spacer component (#17896)
  Add experimental `ResponsiveBlockControl` component (#16790)
  Fix mover for floats. (#18230)
  Rename Component to WPComponent in docstring (#18226)
  Colors Selector: replace `Aa` text by SVG icon (#18222)
  Removed gif from README (#18200)
  makes the submenu items stacked vertically (#18221)
  Add block navigator to sidebar panel for nav block (#18202)
  Fix: consecutive updates may trigger a blocks reset (#18219)
  ...
@youknowriad youknowriad added this to the Gutenberg 6.9 milestone Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigation menu missing default items
3 participants