Skip to content

Commit de128f2

Browse files
committed
Add try/catch around fastSearch tree dispose
1 parent 44e4e11 commit de128f2

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

src/hooks/useFastSearchFromOptions.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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(
@@ -162,7 +170,22 @@ function useFastSearchFromOptions(
162170
});
163171
}, [options]);
164172

165-
useEffect(() => () => prevFastSearchRef.current?.dispose(), []);
173+
useEffect(
174+
() => () => {
175+
try {
176+
Log.info('[CMD_K_DEBUG] FastSearch tree cleanup (reason: unmount)', false, {
177+
timestamp: Date.now(),
178+
});
179+
prevFastSearchRef.current?.dispose();
180+
} catch (error) {
181+
Log.alert('[CMD_K_FREEZE] FastSearch tree cleanup (reason: unmount) failed', {
182+
error: String(error),
183+
timestamp: Date.now(),
184+
});
185+
}
186+
},
187+
[],
188+
);
166189

167190
const findInSearchTree = useCallback(
168191
(searchInput: string): OptionsListType => {

0 commit comments

Comments
 (0)