From 9b1cb06d4e79c13367f8a81bf00a55c06fbf0f79 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 20 Mar 2026 13:36:58 +0000 Subject: [PATCH] fix: isLoading regression and getEffectiveBindingsMap caching Issue 1: Derive isLoading from cache state so it is true when models haven't loaded yet and no error exists, fixing the brief false flash before the mount effect starts fetching. Issue 2: Memoize getEffectiveBindingsMap via useMemo and expose through a ref so the keydown handler reads a cached map instead of recomputing on every keystroke. Co-authored-by: Leo --- apps/web/src/hooks/use-global-shortcuts.ts | 11 +++++------ apps/web/src/stores/model.ts | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/web/src/hooks/use-global-shortcuts.ts b/apps/web/src/hooks/use-global-shortcuts.ts index 4151771c..42d06ee7 100644 --- a/apps/web/src/hooks/use-global-shortcuts.ts +++ b/apps/web/src/hooks/use-global-shortcuts.ts @@ -129,26 +129,25 @@ export function useGlobalShortcuts({ navigate, isAuthenticated, pathname }: UseG const isMac = useMemo(() => isMacPlatform(), []); const onChatRoute = isChatRoute(pathname); - const bindingsRef = useRef(bindings); - bindingsRef.current = bindings; + const bindingMap = useMemo(() => getEffectiveBindingsMap(bindings, isMac), [bindings, isMac]); + const bindingMapRef = useRef(bindingMap); + bindingMapRef.current = bindingMap; + const isAuthenticatedRef = useRef(isAuthenticated); isAuthenticatedRef.current = isAuthenticated; const navigateRef = useRef(navigate); navigateRef.current = navigate; const onChatRouteRef = useRef(onChatRoute); onChatRouteRef.current = onChatRoute; - const isMacRef = useRef(isMac); - isMacRef.current = isMac; useMountEffect(() => { function onKeyDown(event: KeyboardEvent) { if (event.defaultPrevented || event.repeat || event.isComposing) return; - const bindingMap = getEffectiveBindingsMap(bindingsRef.current, isMacRef.current); const currentBinding = eventToBinding(event); if (!currentBinding) return; - const matched: ShortcutDefinition | undefined = bindingMap.get(currentBinding); + const matched: ShortcutDefinition | undefined = bindingMapRef.current.get(currentBinding); if (!matched) return; if (!isAuthenticatedRef.current) return; diff --git a/apps/web/src/stores/model.ts b/apps/web/src/stores/model.ts index 27e820b8..604218ec 100644 --- a/apps/web/src/stores/model.ts +++ b/apps/web/src/stores/model.ts @@ -143,7 +143,7 @@ export function useModels() { }); const models = cache.models ?? getFallbackModels(); - const isLoading = cache.loading; + const isLoading = cache.loading || (cache.models === null && cache.error === null); const error = cache.error; const reload = useCallback(async () => {