@@ -163,9 +163,10 @@ export const createTree = <T>(
163163 // TODO this is never used, remove
164164 } ,
165165 setMounted : ( { } , isMounted ) => {
166- const ref = treeDataRef as TreeDataRef ;
167- treeDataRef . current . isMounted = isMounted ;
166+ const ref = treeDataRef . current as TreeDataRef ;
167+ ref . isMounted = isMounted ;
168168 if ( isMounted ) {
169+ console . log ( "apply waiting" , ref . waitingForMount ?. length ) ;
169170 ref . waitingForMount ?. forEach ( ( cb ) => cb ( ) ) ;
170171 ref . waitingForMount = [ ] ;
171172 }
@@ -185,16 +186,29 @@ export const createTree = <T>(
185186 } ;
186187 const ref = treeDataRef . current as TreeDataRef ;
187188 if ( ref . isMounted ) {
189+ console . log ( "apply substate now" ) ;
188190 apply ( ) ;
189191 } else {
192+ console . log ( "apply substate later" ) ;
190193 ref . waitingForMount ??= [ ] ;
191194 ref . waitingForMount . push ( apply ) ;
192195 }
193196 } ,
194197 // TODO rebuildSubTree: (itemId: string) => void;
195198 rebuildTree : ( ) => {
196- rebuildItemMeta ( ) ;
197- config . setState ?.( state ) ;
199+ const ref = treeDataRef . current as TreeDataRef ;
200+ if ( ref . isMounted ) {
201+ rebuildItemMeta ( ) ;
202+ config . setState ?.( state ) ;
203+ console . log ( "rebuild now" ) ;
204+ } else {
205+ ref . waitingForMount ??= [ ] ;
206+ ref . waitingForMount . push ( ( ) => {
207+ rebuildItemMeta ( ) ;
208+ config . setState ?.( state ) ;
209+ } ) ;
210+ console . log ( "rebuild later" ) ;
211+ }
198212 } ,
199213 scheduleRebuildTree : ( ) => {
200214 rebuildScheduled = true ;
0 commit comments