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 converting a reusable block with nested blocks into a static block #11188

Merged
merged 2 commits into from
Oct 30, 2018

Conversation

noisysocks
Copy link
Member

Fixes #9278.

The CONVERT_BLOCK_TO_STATIC effect needs to handle the case where the block being converted has inner blocks.

Testing

  1. Insert a Columns block.
  2. Insert some other block into the Columns block.
  3. Open the ellipsis (More Options) menu and choose Add to Reusable Blocks.
  4. Finish naming and saving the Reusable Block.
  5. Notice that the nested blocks are saved in the Reusable Block as expected.
  6. Open the ellipsis menu again and choose Convert to Regular Block.
  7. The nested blocks should not have disappeared.

The CONVERT_BLOCK_TO_STATIC effect needs to handle the case where the
block being converted has inner blocks.
@noisysocks noisysocks added [Type] Bug An existing feature does not function as intended [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) labels Oct 29, 2018
@noisysocks noisysocks added this to the 4.2 milestone Oct 29, 2018
@noisysocks noisysocks removed this from the 4.2 milestone Oct 29, 2018
@noisysocks noisysocks added the [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P label Oct 29, 2018
newBlocks = [ createBlock(
referencedBlock.name,
referencedBlock.attributes,
referencedBlock.innerBlocks
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should clone the blocks before calling this:

  • Insert the reusable block twice
  • Convert one of them to regular
  • Edit the regular blocks (notice they change in both blocks)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Fixed in a7464db.

By using cloneBlock(), we correctly make a copy of the innerBlocks which
means that updates to one block don't affect another.
@slimmilkduds
Copy link

slimmilkduds commented Oct 30, 2018

Can you please reconsider and include this in 4.2? I know I’m been nagging about this issue and I promise this is the last time, whatever you decide 😁

@noisysocks noisysocks added this to the 4.2 milestone Oct 30, 2018
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@youknowriad youknowriad merged commit 01b4860 into master Oct 30, 2018
@youknowriad youknowriad deleted the fix/attaching-reusable-nested-blocks branch October 30, 2018 07:54
@talldan
Copy link
Contributor

talldan commented Oct 30, 2018

@noisysocks - sorry - was a bit slow to review this. The only thing I spotted is that I can now nest a reusable block inside of itself, which causes an infinite recursion and my chrome tab ran out of memory!

I know, I know, but I had to try it! 🤣

Want me to create an issue about that?

@youknowriad
Copy link
Contributor

@talldan I don't think it's related to this PR but I saw an issue about it (created yesterday I think)

@talldan
Copy link
Contributor

talldan commented Oct 30, 2018

Thanks, found it - #11206

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 [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants