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

Implementing two innerBlocks inside a custom block results in shared state between the two components #19793

Closed
inspirewebdesigns opened this issue Jan 21, 2020 · 3 comments
Labels
[Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@inspirewebdesigns
Copy link

inspirewebdesigns commented Jan 21, 2020

Describe the bug
When creating a custom block with two InnerBlocks next to each other they share the same state, duplicate the InspectorControls in the sidebar and cause high CPU load resulting in page lag.

To reproduce
Steps to reproduce the behavior:

  1. Create a block with two InnerBlocks in the Edit Callback
  2. Add the block to a page
  3. Try edit the block, and look at the InspectorControls
  4. Encounter duplicate behavior of the two blocks, both blocks share the same state and the InspectorControls options are duplicated. Also encounter high CPU load and page lag.

Expected behavior
Each InnerBlock to have it own state, a single InspectorControls options for each InnerBlock, normal CPU load and no page lag.

Screenshots
Bug
Bug

Code
bug_code

Desktop:

  • OS: Linux Ubuntu
  • Browser: Firefox

Additional context

  • WordPress 5.3.2
@chrisvanpatten
Copy link
Member

@solutions4theweb Two InnerBlocks areas are not supported within a block, because you can't currently serialize it as two separate areas (the block serialization format only supports one innerBlocks area).

Typically the suggestion is to have a single InnerBlocks area which has a template with two blocks which each support their own InnerBlocks area.

@chrisvanpatten chrisvanpatten added [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] Help Request Help with setup, implementation, or "How do I?" questions. labels Jan 21, 2020
@chrisvanpatten
Copy link
Member

Perhaps this is something that we could catch, and use the @wordpress/warning package introduced in #19317 to display a console message?

@inspirewebdesigns
Copy link
Author

inspirewebdesigns commented Jan 21, 2020

Hi @chrisvanpatten, thanks for your blazingly fast reply!

That makes a lot of sense, the actual use case where I discovered this was when I was creating a Slider Block where each Slide has its own InnerBlock. A warning message would be incredibly helpful in identifying this when its not immediately obvious that multiple InnerBlocks are being rendered.

The typical suggestion you mentioned is the way to go, and would definitely cover my use case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

3 participants