From 231c3f76fdbcaecb93770b06d824e031f4f89037 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 30 Jun 2022 20:59:14 +0200 Subject: [PATCH 1/2] Site Editor: Make Code Editor reflect block conversions --- .../src/components/code-editor/index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/edit-site/src/components/code-editor/index.js b/packages/edit-site/src/components/code-editor/index.js index f1a3ea0a13f073..34ef8c485c11b2 100644 --- a/packages/edit-site/src/components/code-editor/index.js +++ b/packages/edit-site/src/components/code-editor/index.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { parse } from '@wordpress/blocks'; +import { parse, __unstableSerializeAndClean } from '@wordpress/blocks'; import { useEntityBlockEditor, useEntityProp } from '@wordpress/core-data'; import { useSelect, useDispatch } from '@wordpress/data'; import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; @@ -32,10 +32,17 @@ export default function CodeEditor() { 'postType', templateType ); - const content = - contentStructure instanceof Function - ? contentStructure( { blocks } ) - : contentStructure; + + // Replicates the logic found in getEditedPostContent(). + let content; + if ( contentStructure instanceof Function ) { + content = contentStructure( { blocks } ); + } else if ( blocks ) { + content = __unstableSerializeAndClean( blocks ); + } else { + content = contentStructure; + } + const { switchEditorMode } = useDispatch( editSiteStore ); return (
From 8613bb967edfa0ae8f3c638e61e48854db44f685 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 30 Jun 2022 21:05:31 +0200 Subject: [PATCH 2/2] Add comment --- packages/edit-site/src/components/code-editor/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/edit-site/src/components/code-editor/index.js b/packages/edit-site/src/components/code-editor/index.js index 34ef8c485c11b2..178ff2e5f7099c 100644 --- a/packages/edit-site/src/components/code-editor/index.js +++ b/packages/edit-site/src/components/code-editor/index.js @@ -38,6 +38,9 @@ export default function CodeEditor() { if ( contentStructure instanceof Function ) { content = contentStructure( { blocks } ); } else if ( blocks ) { + // If we have parsed blocks already, they should be our source of truth. + // Parsing applies block deprecations and legacy block conversions that + // unparsed content will not have. content = __unstableSerializeAndClean( blocks ); } else { content = contentStructure;