Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions packages/block-editor/src/components/provider/use-block-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,25 @@ export default function useBlockSync( {
// and so it would already be persisted.
__unstableMarkNextChangeAsNotPersistent();
if ( clientId ) {
const blockName = getBlockName( clientId );
const isPostContentBlock = blockName === 'core/post-content';

// It is important to batch here because otherwise,
// as soon as `setHasControlledInnerBlocks` is called
// the effect to restore might be triggered
// before the actual blocks get set properly in state.
registry.batch( () => {
setHasControlledInnerBlocks( clientId, true );
const storeBlocks = controlledBlocks.map( ( block ) =>
cloneBlock( block )
);

// For post-content block children, preserve the
// original blocks to maintain UUIDs used for
// multi-user collaboration
//
// Unsure: Why are these blocks being cloned? Do they need to be?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have this code change in for discussion, but this comment should probably be removed before merging.

const storeBlocks = isPostContentBlock
? controlledBlocks
: controlledBlocks.map( ( block ) => cloneBlock( block ) );

if ( subscribedRef.current ) {
pendingChangesRef.current.incoming = storeBlocks;
}
Expand Down
Loading