From 596f87180a9a264a5cb2788cf325dcbd4af8ee49 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Mon, 23 Feb 2026 14:04:52 +0100 Subject: [PATCH] BlockListBlock: fix crash when selectedProps are null --- .../src/components/block-list/block.js | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js index d538c3a93ceb2c..04d2cb2a0e9c76 100644 --- a/packages/block-editor/src/components/block-list/block.js +++ b/packages/block-editor/src/components/block-list/block.js @@ -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 @@ -750,7 +775,6 @@ function BlockListBlockProvider( props ) { isLocked = false, canRemove = false, canMove = false, - blockWithoutAttributes, name, attributes, isValid, @@ -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,