Skip to content

Commit

Permalink
List View: Ensure list view block id is unique to the list view insta…
Browse files Browse the repository at this point in the history
…nce (#49944)
  • Loading branch information
andrewserong authored Apr 20, 2023
1 parent 52c529f commit a1456eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,13 @@ function ListViewBlock( {
blockTitle
);

const { isTreeGridMounted, expand, collapse, BlockSettingsMenu } =
useListViewContext();
const {
isTreeGridMounted,
expand,
collapse,
BlockSettingsMenu,
listViewInstanceId,
} = useListViewContext();

const hasSiblings = siblingBlockCount > 0;
const hasRenderedMovers = showBlockMovers && hasSiblings;
Expand Down Expand Up @@ -237,7 +242,7 @@ function ListViewBlock( {
position={ position }
rowCount={ rowCount }
path={ path }
id={ `list-view-block-${ clientId }` }
id={ `list-view-${ listViewInstanceId }-block-${ clientId }` }
data-block={ clientId }
data-expanded={ canExpand ? isExpanded : undefined }
ref={ rowRef }
Expand Down
5 changes: 4 additions & 1 deletion packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import {
useInstanceId,
useMergeRefs,
__experimentalUseFixedWindowList as useFixedWindowList,
} from '@wordpress/compose';
Expand Down Expand Up @@ -90,6 +91,7 @@ function ListViewComponent(
);
}

const instanceId = useInstanceId( ListViewComponent );
const { clientIdsTree, draggedClientIds, selectedClientIds } =
useListViewClientIds( { blocks, rootClientId } );

Expand Down Expand Up @@ -200,14 +202,15 @@ function ListViewComponent(
expand,
collapse,
BlockSettingsMenu,
listViewInstanceId: instanceId,
} ),
[
isMounted.current,
draggedClientIds,
expandedState,
expand,
collapse,
BlockSettingsMenu,
instanceId,
]
);

Expand Down

0 comments on commit a1456eb

Please sign in to comment.