From 2b12d7ad9903607813618e3275cfba3a5248579b Mon Sep 17 00:00:00 2001 From: ingeniumed Date: Wed, 4 Feb 2026 12:47:17 +0100 Subject: [PATCH 1/3] Fix revision restore funtionality when rtc is enabled --- packages/core-data/src/actions.js | 8 ++++++++ packages/core-data/src/utils/crdt.ts | 2 +- packages/sync/src/providers/index.ts | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/actions.js b/packages/core-data/src/actions.js index d0bc2e5df2852c..48bb1a0cdd91bd 100644 --- a/packages/core-data/src/actions.js +++ b/packages/core-data/src/actions.js @@ -21,6 +21,8 @@ import { createBatch } from './batch'; import { STORE_NAME } from './name'; import { LOCAL_EDITOR_ORIGIN, getSyncManager } from './sync'; import logEntityDeprecation from './utils/log-entity-deprecation'; +import { parse } from '@wordpress/blocks'; +import { getRawValue } from './utils/crdt'; /** * Returns an action object used in signalling that authors have been received. @@ -412,6 +414,12 @@ export const editEntityRecord = return acc; }, {} ); + if ( ( ! editsWithMerges.blocks || editsWithMerges.blocks.length === 0 ) && getRawValue( editsWithMerges.content ) ) { + console.log( 'blocks are empty and content is present', JSON.stringify( editsWithMerges, null, 2 ) ); + editsWithMerges.blocks = parse( getRawValue( editsWithMerges.content ) ); + console.log( 'parsed blocks', JSON.stringify( editsWithMerges.blocks, null, 2 ) ); + } + const edit = { kind, name, diff --git a/packages/core-data/src/utils/crdt.ts b/packages/core-data/src/utils/crdt.ts index d47e1d781aa16e..511fb725892d21 100644 --- a/packages/core-data/src/utils/crdt.ts +++ b/packages/core-data/src/utils/crdt.ts @@ -422,7 +422,7 @@ export const defaultSyncConfig: SyncConfig< BaseState > = { * @param {unknown} value The value to extract from. * @return {string|undefined} The raw string value, or undefined if it could not be determined. */ -function getRawValue( value?: unknown ): string | undefined { +export function getRawValue( value?: unknown ): string | undefined { // Value may be a string property or a nested object with a `raw` property. if ( 'string' === typeof value ) { return value; diff --git a/packages/sync/src/providers/index.ts b/packages/sync/src/providers/index.ts index fce0d441522e54..79925c3f80df87 100644 --- a/packages/sync/src/providers/index.ts +++ b/packages/sync/src/providers/index.ts @@ -46,7 +46,7 @@ export function getProviderCreators(): ProviderCreator[] { */ const filteredProviderCreators: unknown = applyFilters( 'sync.providers', - [] // Replace with `getDefaultProviderCreators()` to enable sync + getDefaultProviderCreators() // Replace with `getDefaultProviderCreators()` to enable sync ); // If the returned value is not an array, ignore and set to empty array. From 78d040b115fa3329db59b7b7190a8c1e9e1db8c9 Mon Sep 17 00:00:00 2001 From: ingeniumed Date: Wed, 4 Feb 2026 13:29:57 +0100 Subject: [PATCH 2/3] Remove the unnecessary workarounds --- packages/core-data/src/actions.js | 19 +++++++++++++------ packages/sync/src/providers/index.ts | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/core-data/src/actions.js b/packages/core-data/src/actions.js index 48bb1a0cdd91bd..296cf9242c8867 100644 --- a/packages/core-data/src/actions.js +++ b/packages/core-data/src/actions.js @@ -8,6 +8,7 @@ import { v4 as uuid } from 'uuid'; * WordPress dependencies */ import apiFetch from '@wordpress/api-fetch'; +import { parse } from '@wordpress/blocks'; import { addQueryArgs } from '@wordpress/url'; import deprecated from '@wordpress/deprecated'; @@ -20,9 +21,8 @@ import { DEFAULT_ENTITY_KEY } from './entities'; import { createBatch } from './batch'; import { STORE_NAME } from './name'; import { LOCAL_EDITOR_ORIGIN, getSyncManager } from './sync'; -import logEntityDeprecation from './utils/log-entity-deprecation'; -import { parse } from '@wordpress/blocks'; import { getRawValue } from './utils/crdt'; +import logEntityDeprecation from './utils/log-entity-deprecation'; /** * Returns an action object used in signalling that authors have been received. @@ -414,10 +414,17 @@ export const editEntityRecord = return acc; }, {} ); - if ( ( ! editsWithMerges.blocks || editsWithMerges.blocks.length === 0 ) && getRawValue( editsWithMerges.content ) ) { - console.log( 'blocks are empty and content is present', JSON.stringify( editsWithMerges, null, 2 ) ); - editsWithMerges.blocks = parse( getRawValue( editsWithMerges.content ) ); - console.log( 'parsed blocks', JSON.stringify( editsWithMerges.blocks, null, 2 ) ); + // When a revision is restored, the blocks are empty but the content is present. + // This causes the other collaborators to lose their content. + // So the workaround is to parse the content and set the blocks. + if ( + ( ! editsWithMerges.blocks || + editsWithMerges.blocks.length === 0 ) && + getRawValue( editsWithMerges.content ) + ) { + editsWithMerges.blocks = parse( + getRawValue( editsWithMerges.content ) + ); } const edit = { diff --git a/packages/sync/src/providers/index.ts b/packages/sync/src/providers/index.ts index 79925c3f80df87..fce0d441522e54 100644 --- a/packages/sync/src/providers/index.ts +++ b/packages/sync/src/providers/index.ts @@ -46,7 +46,7 @@ export function getProviderCreators(): ProviderCreator[] { */ const filteredProviderCreators: unknown = applyFilters( 'sync.providers', - getDefaultProviderCreators() // Replace with `getDefaultProviderCreators()` to enable sync + [] // Replace with `getDefaultProviderCreators()` to enable sync ); // If the returned value is not an array, ignore and set to empty array. From d56d1091b6955cd6d40a44264665d80ca06bd8d9 Mon Sep 17 00:00:00 2001 From: ingeniumed Date: Thu, 5 Feb 2026 10:28:54 +0100 Subject: [PATCH 3/3] Parse out the blocks when a revision is restored --- packages/core-data/src/actions.js | 15 --------------- packages/core-data/src/utils/crdt.ts | 2 +- packages/editor/src/store/private-actions.js | 3 +-- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/packages/core-data/src/actions.js b/packages/core-data/src/actions.js index 296cf9242c8867..d0bc2e5df2852c 100644 --- a/packages/core-data/src/actions.js +++ b/packages/core-data/src/actions.js @@ -8,7 +8,6 @@ import { v4 as uuid } from 'uuid'; * WordPress dependencies */ import apiFetch from '@wordpress/api-fetch'; -import { parse } from '@wordpress/blocks'; import { addQueryArgs } from '@wordpress/url'; import deprecated from '@wordpress/deprecated'; @@ -21,7 +20,6 @@ import { DEFAULT_ENTITY_KEY } from './entities'; import { createBatch } from './batch'; import { STORE_NAME } from './name'; import { LOCAL_EDITOR_ORIGIN, getSyncManager } from './sync'; -import { getRawValue } from './utils/crdt'; import logEntityDeprecation from './utils/log-entity-deprecation'; /** @@ -414,19 +412,6 @@ export const editEntityRecord = return acc; }, {} ); - // When a revision is restored, the blocks are empty but the content is present. - // This causes the other collaborators to lose their content. - // So the workaround is to parse the content and set the blocks. - if ( - ( ! editsWithMerges.blocks || - editsWithMerges.blocks.length === 0 ) && - getRawValue( editsWithMerges.content ) - ) { - editsWithMerges.blocks = parse( - getRawValue( editsWithMerges.content ) - ); - } - const edit = { kind, name, diff --git a/packages/core-data/src/utils/crdt.ts b/packages/core-data/src/utils/crdt.ts index 511fb725892d21..d47e1d781aa16e 100644 --- a/packages/core-data/src/utils/crdt.ts +++ b/packages/core-data/src/utils/crdt.ts @@ -422,7 +422,7 @@ export const defaultSyncConfig: SyncConfig< BaseState > = { * @param {unknown} value The value to extract from. * @return {string|undefined} The raw string value, or undefined if it could not be determined. */ -export function getRawValue( value?: unknown ): string | undefined { +function getRawValue( value?: unknown ): string | undefined { // Value may be a string property or a nested object with a `raw` property. if ( 'string' === typeof value ) { return value; diff --git a/packages/editor/src/store/private-actions.js b/packages/editor/src/store/private-actions.js index 74eaa732d3b50c..7c8edeee2f0bce 100644 --- a/packages/editor/src/store/private-actions.js +++ b/packages/editor/src/store/private-actions.js @@ -614,9 +614,8 @@ export const restoreRevision = } // Build the edits object with all restorable fields from the revision. - // Setting blocks to undefined clears edited blocks, forcing a re-parse of content. const edits = { - blocks: undefined, + blocks: parse( revision.content.raw ), content: revision.content.raw, }; if ( revision.title?.raw !== undefined ) {