Skip to content

fix: isLoading regression and getEffectiveBindingsMap keystroke caching#708

Draft
leoisadev1 wants to merge 1 commit intocursor/code-standards-compliance-d243from
cursor/loading-and-shortcuts-regressions-da7a
Draft

fix: isLoading regression and getEffectiveBindingsMap keystroke caching#708
leoisadev1 wants to merge 1 commit intocursor/code-standards-compliance-d243from
cursor/loading-and-shortcuts-regressions-da7a

Conversation

@leoisadev1
Copy link
Copy Markdown
Member

@leoisadev1 leoisadev1 commented Mar 20, 2026

Fixes two regressions introduced in PR #707 (cursor/code-standards-compliance-d243).

Issue 1 — isLoading regression in useModels hook

Problem: After the module-cache refactor, cache.loading initializes as false. On the first render of useModels(), isLoading reads false even though no models have been fetched yet. There's a brief frame where isLoading is incorrectly false before the mount effect starts fetching and flips it to true.

Fix: Derive isLoading from the full cache state:

const isLoading = cache.loading || (cache.models === null && cache.error === null);

This ensures isLoading is true whenever models haven't loaded yet and no error has occurred, covering the initial render before fetchAllModels() kicks in.

Issue 2 — getEffectiveBindingsMap recomputed on every keystroke

Problem: The onKeyDown handler inside useMountEffect called getEffectiveBindingsMap(bindingsRef.current, isMacRef.current) on every keystroke, creating a new Map each time. While not expensive per-call, it's unnecessary work since bindings only change when the user modifies shortcut settings.

Fix: Memoize the binding map with useMemo and expose it through a ref:

const bindingMap = useMemo(() => getEffectiveBindingsMap(bindings, isMac), [bindings, isMac]);
const bindingMapRef = useRef(bindingMap);
bindingMapRef.current = bindingMap;

The onKeyDown handler reads bindingMapRef.current instead of recomputing. The map is only rebuilt when bindings or isMac changes. Removed the now-unnecessary bindingsRef and isMacRef.

Verification

  • bun check — passes (no new lint warnings)
  • bun run test — all tests pass
  • bun check-types — no type errors in changed files (pre-existing errors in unrelated files)
Open in Web Open in Cursor 

Note

Fix isLoading regression and memoize getEffectiveBindingsMap in keydown handler

  • Fixes isLoading in useModels to return true when both cache.models and cache.error are null, covering the initial indeterminate state that was previously not handled.
  • Replaces per-keydown recomputation of the effective binding map in useGlobalShortcuts with a useMemo-derived map stored in a ref, so the map is only recomputed when bindings or isMac changes.

Macroscope summarized 9b1cb06.

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 <leoisadev1@users.noreply.github.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
osschat-web Ignored Ignored Mar 20, 2026 1:37pm

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Preview Deployment Ready

Vercel is rebuilding the frontend with the new Convex backend URL.

Vercel will post the preview URL automatically.

Convex Preview Backend

  • Cloud URL: https://kindhearted-reindeer-165.convex.cloud
  • Site URL: https://kindhearted-reindeer-165.convex.site

ℹ️ Preview deployments support email/password auth only (GitHub/Vercel OAuth disabled).


🤖 Deployed automatically by GitHub Actions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants