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 pasting content into inner blocks #16717

Merged
merged 3 commits into from Jul 26, 2019

Conversation

@talldan
Copy link
Contributor

commented Jul 23, 2019

Fixes #16645

Description

Resolves an issue where content pasted into inner blocks is not saved correctly.

The issue was caused by a small caching error introduced in #16407.

When pasting content into an empty paragraph, a block replacement is triggered. When this action was being carried out in an inner block, cached parent blocks were not being invalidated.

This is the code that attempts to invalidate parents of a replaced block:
https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/store/reducer.js#L269-L271

The issue is that getBlocksWithParentsClientIds is called with the incorrect clientId. getBlocksWithParentsClientIds operates on the old state rather than the new state, so it needs to be called with the block that's about to be removed rather than the block that's about to be added: https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/store/reducer.js#L228-L237

This PR resolves the issue.

How has this been tested?

Updated the relevant unit test to ensure the parent block is invalidated.

Manual testing:

  1. Add Columns block.
  2. Copy and paste text from another website into each of the columns.
  3. Save the document and preview it.
  4. Observe that the text isn't showing on the frontend.

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

talldan added some commits Jul 23, 2019

Update reducer to omit the replaced clientId, except for when it is t…
…he same as the new client id. Update tests to ensure wrapper generates new key
getBlocksWithParentsClientIds( keys( flattenBlocks( action.blocks ) ) ),
),
...omit( parentClientIds, action.replacedClientIds ),
...fillKeysWithEmptyObject( keys( flattenBlocks( action.blocks ) ) ),

This comment has been minimized.

Copy link
@talldan

talldan Jul 23, 2019

Author Contributor

To explain a bit what I've done here:

  1. The replacedClientIds needs to be used to find parentClientIds, but then replacedClientIds also need to be omitted, hence the second call to omit here.
  2. The new block clientId needs to be included in the cache, and there's a unit test should replace the block even if the new block clientId is the same, so that's why the last object spread is adding the new client id.

This comment has been minimized.

Copy link
@youknowriad

youknowriad Jul 26, 2019

Contributor

The logic seems good to me.

@talldan talldan added this to the Gutenberg 6.2 milestone Jul 23, 2019

@tellthemachines
Copy link
Contributor

left a comment

Tested with columns and nested columns, by pasting content in, saving and previewing, and it's working fine.
Code looks good, thanks for documenting everything so thoroughly!
A thought about the reducer unit tests in general: I wonder if we shouldn't be more granular with what we're testing. There's a huge amount of assertions inside some of those tests, so if they fail, it's not immediately obvious why. E.g. should we have a test to check caching in block replacement, instead of having that check be part of the block replacement test?

@youknowriad youknowriad merged commit 297396b into master Jul 26, 2019

1 of 8 checks passed

Milestone It Milestone It
Details
Milestone It Milestone It
Details
Milestone It Milestone It
Details
Milestone It Milestone It
Details
Milestone It Milestone It
Details
Milestone It Milestone It
Details
Milestone It Milestone It
Details
Travis CI - Pull Request Build Passed
Details

@youknowriad youknowriad deleted the fix/pasting-into-inner-blocks branch Jul 26, 2019

sbardian added a commit to sbardian/gutenberg that referenced this pull request Jul 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.