@@ -741,6 +741,31 @@ function BlockListBlockProvider( props ) {
741741 [ clientId , rootClientId ]
742742 ) ;
743743
744+ // Use block visibility hook with data from existing useSelect to avoid extra subscription
745+ const { isBlockCurrentlyHidden } = useBlockVisibility ( {
746+ blockVisibility : selectedProps ?. blockVisibility ,
747+ deviceType : selectedProps ?. deviceType ,
748+ } ) ;
749+
750+ // Users of the editor.BlockListBlock filter used to be able to
751+ // access the block prop.
752+ // Ideally these blocks would rely on the clientId prop only.
753+ // This is kept for backward compatibility reasons.
754+ const block = useMemo (
755+ ( ) => ( {
756+ ...selectedProps ?. blockWithoutAttributes ,
757+ attributes : selectedProps ?. attributes ,
758+ } ) ,
759+ [ selectedProps ?. blockWithoutAttributes , selectedProps ?. attributes ]
760+ ) ;
761+
762+ // Block is sometimes not mounted at the right time, causing it be
763+ // undefined see issue for more info
764+ // https://github.com/WordPress/gutenberg/issues/17013
765+ if ( ! selectedProps ) {
766+ return null ;
767+ }
768+
744769 const {
745770 isPreviewMode,
746771 // Fill values that end up as a public API and may not be defined in
@@ -750,7 +775,6 @@ function BlockListBlockProvider( props ) {
750775 isLocked = false ,
751776 canRemove = false ,
752777 canMove = false ,
753- blockWithoutAttributes,
754778 name,
755779 attributes,
756780 isValid,
@@ -786,28 +810,6 @@ function BlockListBlockProvider( props ) {
786810 deviceType,
787811 } = selectedProps ;
788812
789- // Use block visibility hook with data from existing useSelect to avoid extra subscription
790- const { isBlockCurrentlyHidden } = useBlockVisibility ( {
791- blockVisibility,
792- deviceType,
793- } ) ;
794-
795- // Users of the editor.BlockListBlock filter used to be able to
796- // access the block prop.
797- // Ideally these blocks would rely on the clientId prop only.
798- // This is kept for backward compatibility reasons.
799- const block = useMemo (
800- ( ) => ( { ...blockWithoutAttributes , attributes } ) ,
801- [ blockWithoutAttributes , attributes ]
802- ) ;
803-
804- // Block is sometimes not mounted at the right time, causing it be
805- // undefined see issue for more info
806- // https://github.com/WordPress/gutenberg/issues/17013
807- if ( ! selectedProps ) {
808- return null ;
809- }
810-
811813 const privateContext = {
812814 isPreviewMode,
813815 clientId,
0 commit comments