@@ -108,12 +108,20 @@ function useFastSearchFromOptions(
108108 // Dispose existing tree if present
109109 if ( prevFastSearchRef . current ) {
110110 const disposeStartTime = Date . now ( ) ;
111- prevFastSearchRef . current . dispose ( ) ;
112- Log . info ( '[CMD_K_DEBUG] FastSearch tree disposed' , false , {
113- actionId,
114- disposeTime : Date . now ( ) - disposeStartTime ,
115- timestamp : Date . now ( ) ,
116- } ) ;
111+ try {
112+ prevFastSearchRef . current . dispose ( ) ;
113+ Log . info ( '[CMD_K_DEBUG] FastSearch tree disposed (reason: recreate)' , false , {
114+ actionId,
115+ disposeTime : Date . now ( ) - disposeStartTime ,
116+ timestamp : Date . now ( ) ,
117+ } ) ;
118+ } catch ( error ) {
119+ Log . alert ( '[CMD_K_FREEZE] FastSearch tree disposed (reason: recreate) failed' , {
120+ actionId,
121+ error : String ( error ) ,
122+ timestamp : Date . now ( ) ,
123+ } ) ;
124+ }
117125 }
118126
119127 newFastSearch = FastSearch . createFastSearch (
@@ -160,27 +168,24 @@ function useFastSearchFromOptions(
160168 throw error ;
161169 }
162170 } ) ;
171+ } , [ options ] ) ;
163172
164- return ( ) => {
173+ useEffect (
174+ ( ) => ( ) => {
165175 try {
166- if ( newFastSearch ) {
167- Log . info ( '[CMD_K_DEBUG] FastSearch tree cleanup' , false , {
168- actionId,
169- timestamp : Date . now ( ) ,
170- } ) ;
171- newFastSearch . dispose ( ) ;
172- }
176+ Log . info ( '[CMD_K_DEBUG] FastSearch tree cleanup (reason: unmount)' , false , {
177+ timestamp : Date . now ( ) ,
178+ } ) ;
179+ prevFastSearchRef . current ?. dispose ( ) ;
173180 } catch ( error ) {
174- Log . alert ( '[CMD_K_FREEZE] FastSearch tree cleanup failed' , {
175- actionId,
181+ Log . alert ( '[CMD_K_FREEZE] FastSearch tree cleanup (reason: unmount) failed' , {
176182 error : String ( error ) ,
177183 timestamp : Date . now ( ) ,
178184 } ) ;
179185 }
180- } ;
181- } , [ options ] ) ;
182-
183- useEffect ( ( ) => ( ) => prevFastSearchRef . current ?. dispose ( ) , [ ] ) ;
186+ } ,
187+ [ ] ,
188+ ) ;
184189
185190 const findInSearchTree = useCallback (
186191 ( searchInput : string ) : OptionsListType => {
0 commit comments