Skip to content
Merged
Show file tree
Hide file tree
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
53 changes: 34 additions & 19 deletions packages/blocks/src/api/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,28 +396,43 @@ export function serializeBlock( block, { isInnerBlocks = false } = {} ) {
return getCommentDelimitedContent( blockName, saveAttributes, saveContent );
}

export function __unstableSerializeAndClean( blocks ) {
// A single unmodified default block is assumed to
// be equivalent to an empty post.
if ( blocks.length === 1 && isUnmodifiedDefaultBlock( blocks[ 0 ] ) ) {
blocks = [];
}
export const __unstableSerializeAndClean = ( () => {
const cache = new WeakMap();

let content = serialize( blocks );
return ( blocks ) => {
const cached = cache.get( blocks );
if ( cached !== undefined ) {
return cached;
}

// For compatibility, treat a post consisting of a
// single freeform block as legacy content and apply
// pre-block-editor removep'd content formatting.
if (
blocks.length === 1 &&
blocks[ 0 ].name === getFreeformContentHandlerName() &&
blocks[ 0 ].name === 'core/freeform'
) {
content = removep( content );
}
let effectiveBlocks = blocks;

return content;
}
// A single unmodified default block is assumed to
// be equivalent to an empty post.
if (
effectiveBlocks.length === 1 &&
isUnmodifiedDefaultBlock( effectiveBlocks[ 0 ] )
) {
effectiveBlocks = [];
}

let content = serialize( effectiveBlocks );

// For compatibility, treat a post consisting of a
// single freeform block as legacy content and apply
// pre-block-editor removep'd content formatting.
if (
effectiveBlocks.length === 1 &&
effectiveBlocks[ 0 ].name === getFreeformContentHandlerName() &&
effectiveBlocks[ 0 ].name === 'core/freeform'
) {
content = removep( content );
}

cache.set( blocks, content );
return content;
};
} )();

/**
* Takes a block or set of blocks and returns the serialized post content.
Expand Down
2 changes: 0 additions & 2 deletions packages/core-data/src/utils/crdt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ export function getPostChangesFromCRDTDoc(
);
}

// The consumers of blocks have memoization that renders optimization
// here unnecessary.
return true;
}

Expand Down
Loading