Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Content: Fix display of block support styles #66003

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
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
26 changes: 25 additions & 1 deletion packages/block-library/src/post-content/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import {
RecursionProvider,
useHasRecursion,
Warning,
__experimentalUseBlockPreview as useBlockPreview,
} from '@wordpress/block-editor';
import { parse } from '@wordpress/blocks';
import {
useEntityProp,
useEntityBlockEditor,
store as coreStore,
} from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
*/
Expand All @@ -33,7 +37,27 @@ function ReadOnlyContent( {
postId
);
const blockProps = useBlockProps( { className: layoutClassNames } );
return content?.protected && ! userCanEdit ? (
const blocks = useMemo( () => {
return content?.raw ? parse( content.raw ) : [];
}, [ content?.raw ] );
const blockPreviewProps = useBlockPreview( {
blocks,
props: blockProps,
} );

if ( userCanEdit ) {
/*
* Rendering the block preview using the raw content blocks allows for
* block support styles to be generated and applied by the editor.
*
* The preview using the raw blocks can only be presented to users with
* edit permissions for the post to prevent potential exposure of private
* block content.
*/
return <div { ...blockPreviewProps }></div>;
}

return content?.protected ? (
<div { ...blockProps }>
<Warning>{ __( 'This content is password protected.' ) }</Warning>
</div>
Expand Down
Loading