File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
packages/react/src/composite/list Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -41,8 +41,27 @@ export function CompositeList<Metadata>(props: CompositeList.Props<Metadata>) {
4141
4242 useIsoLayoutEffect ( ( ) => {
4343 if ( ! mapDirty ) {
44- return ;
44+ if ( typeof MutationObserver !== 'function' ) {
45+ return undefined ;
46+ }
47+
48+ const parents = new Set < Element > ( ) ;
49+ const mutationObserver = new MutationObserver ( ( ) => {
50+ setMapDirty ( true ) ;
51+ } ) ;
52+
53+ mapRef . current . forEach ( ( _ , node ) => {
54+ if ( node . parentElement && ! parents . has ( node . parentElement ) ) {
55+ parents . add ( node . parentElement ) ;
56+ mutationObserver . observe ( node . parentElement , { childList : true } ) ;
57+ }
58+ } ) ;
59+
60+ return ( ) => {
61+ mutationObserver . disconnect ( ) ;
62+ } ;
4563 }
64+
4665 const newMap = new Map < Element , CompositeMetadata < Metadata > > ( ) ;
4766 const sortedNodes = Array . from ( mapRef . current . keys ( ) ) . sort ( sortByDocumentPosition ) ;
4867
@@ -52,6 +71,8 @@ export function CompositeList<Metadata>(props: CompositeList.Props<Metadata>) {
5271 } ) ;
5372 mapRef . current = newMap ;
5473 setMapDirty ( false ) ;
74+
75+ return undefined ;
5576 } , [ mapDirty , mapRef ] ) ;
5677
5778 const sortedMap = mapRef . current ;
You can’t perform that action at this time.
0 commit comments