-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
…the correct parent blocks
…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 ) ) ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To explain a bit what I've done here:
- The
replacedClientIds
needs to be used to find parentClientIds, but thenreplacedClientIds
also need to be omitted, hence the second call toomit
here. - 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic seems good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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-L237This PR resolves the issue.
How has this been tested?
Updated the relevant unit test to ensure the parent block is invalidated.
Manual testing:
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: