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: Another paragraph is inserted, inside InnerBlocks. #10733

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Oct 18, 2018

Currently, we have a bug even if a block has a paragraph as the last block of the template if no locking exists another paragraph is inserted.

This happens because, before the template is processed the parent block is empty and DefaultBlockApppender is rendered right away. DefaultBlockApppender inserts blocks when it gets focused. The parent block has a mechanism to focus the first table and if InnerBlocks were not yet processed and the parent block does not contain inputs the DefaultBlockApppender is going to get the focus.

Before the template is processed we don't know what blocks will exist so during this phase DefaultBlockApppender should not be rendered. This PR makes sure that we don't render DefaultBlockApppender right after the block is inserted before the template is processed.

This behavior was noticed in #9416.

How has this been tested?

I added the test block available in https://gist.github.com/jorgefilipecosta/edafb2422ef41020d75619adf31d725e.

I checked that after inserting the first paragraph specified in the template gets focused and no other paragraph is created.

I checked the blocks depending on the behavior of DefaultBlockApppender inserting a block (columns) continue to work as before.

Screenshots

test block: https://gist.github.com/jorgefilipecosta/edafb2422ef41020d75619adf31d725e

	var TEMPLATE = [
		[ 'core/paragraph', { placeholder: 'Paragraph 1', customFontSize: 35 } ],
	];

After:

screen shot 2018-10-18 at 13 07 03

screen shot 2018-10-18 at 13 06 54

Before:

screen shot 2018-10-18 at 13 17 27

screen shot 2018-10-18 at 13 17 21

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P labels Oct 18, 2018
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Do we need to wait until componentDidMount to sync the template, or can it be done in componentWillMount?

Alternatively, can we not render BlockList until after the sync?

For what reason do we pass template to BlockList? The responsibilities are fuzzy to me, and makes me wonder if it's not BlockList to be synchronizing the template. But as I look to BlockList, it doesn't appear we should be passing it (it's unused)?

Honestly, this feels like something where we're being punished for our non-ideal implementation of InnerBlocks template managing blocks state in response to lifecycle, rather than having more strict rendering control of blocks in a BlocksList (i.e. value or blocks property, similar to some ideas @youknowriad has expressed around <Editor value={ ... } onChange={ ... } />).

@jorgefilipecosta jorgefilipecosta force-pushed the fix/bug-another-paragraph-is-inserted-even-if-template-already-contains-one branch from b748a47 to dd6a5f9 Compare October 23, 2018 20:45
@jorgefilipecosta
Copy link
Member Author

Thank you for your review @aduth!

Do we need to wait until componentDidMount to sync the template, or can it be done in componentWillMount?

I think it can be done in componentWillMount, and it worked correctly in my tests if the only change is replacing componentDidMount with componentWillMount. I did not use this approach because componentWillMount will be deprecated.

Alternatively, can we not render BlockList until after the sync?

For what reason do we pass template to BlockList? The responsibilities are fuzzy to me, and makes me wonder if it's not BlockList to be synchronizing the template. But as I look to BlockList, it doesn't appear we should be passing it (it's unused)?

I like the idea of not rendering BlockList until the sync is done, and it solves the problem of passing template sync info to BlockList. I updated the code to use this approach. Regarding the other template related props, you raised a very important question, I think these props are currently not being used (not certain why they were being passed probably they were needed before). I added a commit that removes them.

Honestly, this feels like something where we're being punished for our non-ideal implementation of InnerBlocks template managing blocks state in response to lifecycle, rather than having more strict rendering control of blocks in a BlocksList (i.e. value or blocks property, similar to some ideas @youknowriad has expressed around <Editor value={ ... } onChange={ ... } />).

I agree that having the syntax of <Editor value={ ... } onChange={ ... } /> would be ideal, it is probably a task that we should analyze for the next phase, right now pursuing this approach seems risky.

Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

I don't quite follow the code here, and I think having an E2E test that reproduced the testing instructions here would help to contextualise the code/issue better and also prevent regressions.

Could you add an E2E test for this?

@jorgefilipecosta jorgefilipecosta force-pushed the fix/bug-another-paragraph-is-inserted-even-if-template-already-contains-one branch from 59912cf to 7bbb60c Compare November 13, 2018 11:11
Squashed commits:
[23554fe7b] Fix: Another paragraph is inserted, inside the block even if the block template already includes a paragraph.
[a31f7b2ee] Update snapshot
@jorgefilipecosta jorgefilipecosta force-pushed the fix/bug-another-paragraph-is-inserted-even-if-template-already-contains-one branch from 7bbb60c to 13bda1b Compare November 13, 2018 11:39
@jorgefilipecosta
Copy link
Member Author

jorgefilipecosta commented Nov 13, 2018

Hi @tofumatt thank you for reviewing this PR. We already had an end 2 end test case touching this, the snapshot had the buggy implementation and this PR updated the snapshot. But I agree we could benefit from a test dedicated to this behavior. I added a new end 2 end test specifically for this behavior.

@jorgefilipecosta jorgefilipecosta dismissed tofumatt’s stale review November 13, 2018 21:39

the end 2 end test was added

Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Works for me! 👍

@jorgefilipecosta jorgefilipecosta added this to the 4.4 milestone Nov 14, 2018
@jorgefilipecosta jorgefilipecosta merged commit 66a17f3 into master Nov 14, 2018
@jorgefilipecosta jorgefilipecosta deleted the fix/bug-another-paragraph-is-inserted-even-if-template-already-contains-one branch November 14, 2018 21:27
@jorgefilipecosta
Copy link
Member Author

Thank you for the reviews!

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] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants