Skip to content

Writing Flow: Fix merging blocks after nested blocks refactoring#4911

Merged
youknowriad merged 3 commits intomasterfrom
fix/merging-blocks
Feb 8, 2018
Merged

Writing Flow: Fix merging blocks after nested blocks refactoring#4911
youknowriad merged 3 commits intomasterfrom
fix/merging-blocks

Conversation

@youknowriad
Copy link
Copy Markdown
Contributor

After the nested blocks refactoring, merging blocks is producing a JS error because of undefined innerBlocks in several places. I was not certain if this property is optional or not cc @aduth

The fix here just adds a default value to the property when needed.

Testing instructions

  • Create two paragraphs
  • Press Backspace when the caret is at the beginning of the second paragraph
  • The paragraphs should merge properly.

@youknowriad youknowriad added the [Type] Bug An existing feature does not function as intended label Feb 7, 2018
@youknowriad youknowriad self-assigned this Feb 7, 2018
@youknowriad youknowriad requested a review from aduth February 7, 2018 08:35
@atimmer
Copy link
Copy Markdown
Member

atimmer commented Feb 7, 2018

This sounds like a fix that needs unit tests.

@youknowriad
Copy link
Copy Markdown
Contributor Author

@atimmer It definitely needs unit tests, but It's not ready yet :)

--

I just discovered that innerBlocks are not supposed to be undefined from the parser's code. But it happens that we drop this property when setting blockByUid in the state when calling getFlattenedBlocks which makes sense since the order and inner blocks are kept separate in blockOrder reducer.

But the issue is that calling the getBlock() selector is returning a block without the inner blocks property. So maybe the right fix here is to enhance getBlock to include the innerBlocks. Thoughts @aduth

@aduth
Copy link
Copy Markdown
Member

aduth commented Feb 7, 2018

But the issue is that calling the getBlock() selector is returning a block without the inner blocks property. So maybe the right fix here is to enhance getBlock to include the innerBlocks. Thoughts @aduth

Heh, I had this on my mind in a totally unrelated circumstance, and agree it'd make for a wise change. Currently we only assign this in getBlocks, but it seems like getBlocks should just map to getBlock where the innerBlocks assignment is to occur.

@aduth
Copy link
Copy Markdown
Member

aduth commented Feb 7, 2018

Updated getBlock to assign innerBlocks in 046d694.

@youknowriad
Copy link
Copy Markdown
Contributor Author

These changes look good to me and it's working good right now.

@youknowriad youknowriad merged commit cddbb22 into master Feb 8, 2018
@youknowriad youknowriad deleted the fix/merging-blocks branch February 8, 2018 09:23
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.

3 participants