improvement(chat): defer resource-menu list queries until the menu opens - #5973
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Mention safety while lists load: Cleanup: Removed Reviewed by Cursor Bugbot for commit 6a44068. Configure here. |
Greptile SummaryDefers workspace resource-list queries until relevant menus are opened or warmed.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains in the current follow-up scope.
|
| Filename | Overview |
|---|---|
| apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/add-resource-dropdown/add-resource-dropdown.tsx | Centralizes deferred resource hydration, stable empty groups, and aggregate pending state without an eligible follow-up defect. |
| apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/plus-menu-dropdown/plus-menu-dropdown.tsx | Moves queries behind menu readiness and safely distinguishes hydration from a settled empty candidate list. |
| apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/prompt-editor.tsx | Latches query warming on first editable-textarea focus. |
| apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/use-prompt-editor.ts | Prevents Enter and Tab from falling through while mention candidates are hydrating. |
| apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-tabs/resource-tabs.tsx | Disables tab-name list queries when there are no resource tabs and stabilizes the empty lookup. |
| apps/sim/hooks/queries/workflows.ts | Adds optional query enablement while preserving default behavior. |
| apps/sim/hooks/queries/tables.ts | Adds optional query enablement while preserving existing polling configuration. |
| apps/sim/hooks/queries/folders.ts | Adds optional query enablement alongside the existing workspace guard. |
| apps/sim/hooks/queries/mothership-chats.ts | Adds optional query enablement while retaining skip-token handling. |
| apps/sim/hooks/queries/schedules.ts | Adds optional query enablement alongside the existing workspace guard. |
| apps/sim/hooks/queries/workspace-file-folders.ts | Adds optional query enablement without changing the default fetch behavior. |
Reviews (4): Last reviewed commit: "fix(chat): never submit a mention while ..." | Re-trigger Greptile
The `+` resource menu and the `@`-mention menu both hydrate from `useAvailableResources`, which fired nine workspace-wide list queries and rebuilt ten item groups on mount — from two always-mounted call sites, for menus that were closed. Gate it on each menu's own open state. - add an `enabled` option to `useAvailableResources`; pass `open` from `AddResourceDropdown` and `PlusMenuDropdown` - add `options.enabled` to the six query hooks that lacked it, matching the convention already used by `useWorkspaceFiles` / `useKnowledgeBasesQuery` / `useLogsList` - skip the tab-name lookup's five list queries when there are no tabs to label - drop the `= []` destructuring defaults: a literal default allocates a fresh array every render while `data` is undefined, busting the group memo in exactly the disabled state - move the hook call into `PlusMenuDropdown`, which owns the open state, removing the `availableResources` pass-through from `usePromptEditor` - delete the `existingKeys`/`isOpen` plumbing — one consumer never read it; resolve it at the single call site instead
Deferring the lists to menu-open left a window where `selectActive()` saw an empty candidate list, and its `false` return falls through to submitting the message with the mention unresolved. Start hydrating on first focus — the earliest reliable signal a mention may be coming — which closes the window while keeping the lists off the page-load path.
6e7177e to
8f224ce
Compare
|
@cursor review |
Warming on focus shrank the race but gave no readiness guarantee: an empty candidate list still meant "no match" to the keydown handler, which falls through and submits the message with the mention as raw text. Make the distinction explicit. `useAvailableResources` now reports `isHydrating`, and `PlusMenuHandle.selectActive` returns `selected | empty | hydrating` instead of a boolean. The editor swallows Tab/Enter while hydrating and only lets them through once the lists have settled, where an empty result is a genuine no-match. `isHydrating` keys off `isPending`, not `data === undefined`, so a failed list settles instead of blocking the key forever.
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 6a44068. Configure here.
Summary
+resource menu and the@-mention menu both hydrate fromuseAvailableResources, which fired nine workspace-wide list queries and rebuilt ten item groups on mount — from two always-mounted call sites, for menus that were closed. Now gated on each menu's own state.options.enabledto the six query hooks that lacked it, matching the convention already used byuseWorkspaceFiles/useKnowledgeBasesQuery/useLogsList.= []destructuring defaults in the aggregator — a literal default allocates a fresh array every render whiledataisundefined, which busted the group memo in exactly the disabled state. Disabled now returns a module-scope constant, so the four downstream memos stay stable too.PlusMenuDropdown(the component that owns the open state), removing theavailableResourcespass-through fromusePromptEditor→PromptEditor. This also restores theReact.memoboundary onPlusMenuDropdown, which the array prop was defeating on every keystroke.existingKeys/isOpenplumbing threaded throughAvailableItem, both tree-node unions and bothonSelectsignatures —PlusMenuDropdownnever read it. Resolved at the single call site instead.Not losing mentions while the lists load
Deferring the lists introduced a window where the mention candidates were empty. That mattered more than it first looked:
selectActive()returning falsy makes the keydown handler fall through and submit the message, with the mention left as raw text. Closed in two steps:PlusMenuDropdowngates onopen || warm, andPromptEditorlatcheswarmon the textarea's first focus. Focus is the earliest reliable signal a mention may be coming, so the lists are in flight well before anyone can type@, while still staying off the page-load path.useAvailableResourcesnow reportsisHydratingandPlusMenuHandle.selectActivereturnsselected | empty | hydrating. Tab/Enter are swallowed while hydrating and only fall through once the lists have settled, where an empty result is a genuine no-match.isHydratingkeys offisPendingrather thandata === undefined, so a failed list settles instead of blocking the key forever.Found while investigating a customer report of slow chat loading. Worth being clear about scope: this is a real reduction in work per chat load, but it is not the fix for that report. The dominant costs there are the embedded workflow editor mounting inside the chat, the block/tool registry in the route's initial bundle, and a ~294 KB transcript — all separate follow-ups.
Type of Change
Testing
Tested manually. Typecheck clean,
bun run lint:check19/19, 249 home tests pass,check:react-query/check:api-validation/check:client-boundaryall pass.Checklist