From 7a12baea565a1bf550faf3b48d42c8f731fedd7b Mon Sep 17 00:00:00 2001 From: ingeniumed Date: Thu, 16 Oct 2025 14:17:25 +1100 Subject: [PATCH 1/2] Sync the blocks even if there are errors --- packages/core-data/src/utils/crdt.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core-data/src/utils/crdt.ts b/packages/core-data/src/utils/crdt.ts index fc7b35b2082251..d20c5f97015b48 100644 --- a/packages/core-data/src/utils/crdt.ts +++ b/packages/core-data/src/utils/crdt.ts @@ -65,6 +65,13 @@ export function applyPostChangesToCRDTDoc( switch ( key ) { case 'blocks': { + // Account for the case where the content has some invalid blocks, and as a result + // the blocks are undefined but the content is not. + if ( changes.content && ! changes.blocks ) { + // Pull in the parsed blocks from the content, and use that as the new value. + newValue = parse( getRawValue( changes.content ) ); + } + let currentBlocks = ymap.get( 'blocks' ) as Y.Array< YBlock >; // Initialize. From 513ba20cd7657cb03db5edb1b36393b87a874104 Mon Sep 17 00:00:00 2001 From: ingeniumed Date: Thu, 16 Oct 2025 14:33:30 +1100 Subject: [PATCH 2/2] Add in a try and catch for the block parsing --- packages/core-data/src/utils/crdt.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/utils/crdt.ts b/packages/core-data/src/utils/crdt.ts index d20c5f97015b48..2d1ff58c158e44 100644 --- a/packages/core-data/src/utils/crdt.ts +++ b/packages/core-data/src/utils/crdt.ts @@ -68,8 +68,13 @@ export function applyPostChangesToCRDTDoc( // Account for the case where the content has some invalid blocks, and as a result // the blocks are undefined but the content is not. if ( changes.content && ! changes.blocks ) { - // Pull in the parsed blocks from the content, and use that as the new value. - newValue = parse( getRawValue( changes.content ) ); + try { + // Pull in the parsed blocks from the content, and use that as the new value. + newValue = parse( getRawValue( changes.content ) ); + } catch ( e ) { + // No-op as one of the blocks is expected to be invalid. + // This ensures that neither the blocks, nor the content are overwritten. + } } let currentBlocks = ymap.get( 'blocks' ) as Y.Array< YBlock >;