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
48 changes: 25 additions & 23 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,31 @@ function BlockListBlockProvider( props ) {
[ clientId, rootClientId ]
);

// Use block visibility hook with data from existing useSelect to avoid extra subscription
const { isBlockCurrentlyHidden } = useBlockVisibility( {
blockVisibility: selectedProps?.blockVisibility,
deviceType: selectedProps?.deviceType,
} );

// Users of the editor.BlockListBlock filter used to be able to
// access the block prop.
// Ideally these blocks would rely on the clientId prop only.
// This is kept for backward compatibility reasons.
const block = useMemo(
() => ( {
...selectedProps?.blockWithoutAttributes,
attributes: selectedProps?.attributes,
} ),
[ selectedProps?.blockWithoutAttributes, selectedProps?.attributes ]
);

// Block is sometimes not mounted at the right time, causing it be
// undefined see issue for more info
// https://github.com/WordPress/gutenberg/issues/17013
if ( ! selectedProps ) {
return null;
}

const {
isPreviewMode,
// Fill values that end up as a public API and may not be defined in
Expand All @@ -750,7 +775,6 @@ function BlockListBlockProvider( props ) {
isLocked = false,
canRemove = false,
canMove = false,
blockWithoutAttributes,
name,
attributes,
isValid,
Expand Down Expand Up @@ -786,28 +810,6 @@ function BlockListBlockProvider( props ) {
deviceType,
} = selectedProps;

// Use block visibility hook with data from existing useSelect to avoid extra subscription
const { isBlockCurrentlyHidden } = useBlockVisibility( {
blockVisibility,
deviceType,
} );

// Users of the editor.BlockListBlock filter used to be able to
// access the block prop.
// Ideally these blocks would rely on the clientId prop only.
// This is kept for backward compatibility reasons.
const block = useMemo(
() => ( { ...blockWithoutAttributes, attributes } ),
[ blockWithoutAttributes, attributes ]
);

// Block is sometimes not mounted at the right time, causing it be
// undefined see issue for more info
// https://github.com/WordPress/gutenberg/issues/17013
if ( ! selectedProps ) {
return null;
}

const privateContext = {
isPreviewMode,
clientId,
Expand Down
Loading