Skip to content
Merged
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
20 changes: 15 additions & 5 deletions packages/edit-site/src/components/code-editor/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -32,10 +32,20 @@ export default function CodeEditor() {
'postType',
templateType
);
const content =
contentStructure instanceof Function
? contentStructure( { blocks } )
: contentStructure;

// Replicates the logic found in getEditedPostContent().
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Specifically:

if ( typeof record.content === 'function' ) {
return record.content( record );
} else if ( record.blocks ) {
return __unstableSerializeAndClean( record.blocks );
} else if ( record.content ) {
return record.content;
}

let content;
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;
}

const { switchEditorMode } = useDispatch( editSiteStore );
return (
<div className="edit-site-code-editor">
Expand Down