Spike: Add a client cache layer for new sidebar data using tanstack#10134
Draft
cwangsmv wants to merge 2 commits into
Draft
Spike: Add a client cache layer for new sidebar data using tanstack#10134cwangsmv wants to merge 2 commits into
cwangsmv wants to merge 2 commits into
Conversation
✅ Circular References ReportGenerated at: 2026-06-23T02:52:58.473Z Summary
Click to view all circular references in PR (9)Click to view all circular references in base branch (9)Analysis✅ No Change: This PR does not introduce or remove any circular references. This report was generated automatically by comparing against the |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a TanStack Query–backed in-memory cache for sidebar/project-index data sourced from the local NeDB, and wires database change events to invalidate/patch the query cache so UI consumers can share “warm” data across routes/components.
Changes:
- Adds a shared
QueryClient+ provider and adb.changes→ query-cache bridge to keep cached data in sync with NeDB updates. - Introduces query hooks for projects, workspaces, and workspace-children (including microtask batching for workspace-children reads).
- Migrates the project navigation sidebar + project index page to read from the new hooks instead of ad-hoc local caches / loader-only data.
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/insomnia/src/ui/hooks/data/projects.ts | Adds a useProjects hook and query keys for org-scoped project lists. |
| packages/insomnia/src/ui/hooks/data/workspaces.ts | Adds workspace query keys/hooks and a useLocalFiles helper that composes workspace + child queries. |
| packages/insomnia/src/ui/hooks/data/workspace-children.ts | Adds workspace-children query infra, scope-aware fetchers, and microtask batching. |
| packages/insomnia/src/ui/hooks/data/db-changes-sync.ts | Subscribes to db.changes and invalidates/patches relevant query keys. |
| packages/insomnia/src/ui/context/app/insomnia-query-client.tsx | Defines the shared dbQueryClient and provider that registers the DB-change subscription. |
| packages/insomnia/src/routes/organization.tsx | Wraps the org route UI tree with the TanStack Query provider. |
| packages/insomnia/src/routes/organization.$organizationId.project.$projectId.tsx | Seeds the shared query cache with the project list from the route loader. |
| packages/insomnia/src/routes/organization.$organizationId.project.$projectId._index.tsx | Moves local file computation to the new hooks; loader now fetches workspace metas used by the hook. |
| packages/insomnia/src/ui/components/sidebar/project-navigation-sidebar/project-navigation-sidebar.tsx | Replaces custom refs/state caching with query hooks and adds optimistic cache updates for collapse state changes. |
| packages/insomnia/src/ui/components/sidebar/project-navigation-sidebar/project-node.tsx | Computes presence + git status within the node and passes derived status into the dropdown. |
| packages/insomnia/src/ui/components/sidebar/project-navigation-sidebar/types.ts | Updates sidebar project type shape (removes embedded presence). |
| packages/insomnia/src/ui/components/sidebar/project-navigation-sidebar/project-navigation-sidebar-utils.ts | Adapts collection flattening utility to the new CollectionWorkspaceChildren structure. |
| packages/insomnia/src/ui/components/sidebar/project-navigation-sidebar/project-navigation-sidebar-utils.test.ts | Updates unit tests to use the new CollectionWorkspaceChildren shape (removes DB-backed tests). |
| packages/insomnia/src/ui/components/settings/import-export.tsx | Moves workspaceCount retrieval from root loader to component-side effect. |
| packages/insomnia/src/root.tsx | Removes workspaceCount from root loader data. |
| packages/insomnia/package.json | Adds @tanstack/react-query dependency for the renderer package. |
| package-lock.json | Locks @tanstack/react-query / @tanstack/query-core dependency additions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+38
to
+42
| export const useWorkspace = (workspaceId: string, projectId: string): UseQueryResult<Workspace | undefined> => | ||
| useQuery({ | ||
| queryKey: workspaceKeys.detail(projectId, workspaceId), | ||
| queryFn: () => getWorkspaceById(workspaceId), | ||
| }); |
Comment on lines
+450
to
+454
| const batch = Promise.resolve().then(() => { | ||
| pendingBatches.delete(scopeKey); | ||
| console.log(`Batching requests/meta load for workspaces (${scopeKey}): ${ids.join(', ')}`); | ||
| return getWorkspaceChildren(ids, scope); | ||
| }); |
Comment on lines
+246
to
+259
| const collectionWorkspaceIds = useMemo(() => { | ||
| const ids: string[] = []; | ||
| projectIds.forEach(projectId => { | ||
| (workspacesByProjectId.get(projectId) || []).forEach(workspace => { | ||
| if ( | ||
| workspace.scope === 'collection' && | ||
| (!!projectNavigationSidebarFilter || (expandedProjectAndWorkspaceIds || []).includes(workspace._id)) | ||
| ) { | ||
| ids.push(workspace._id); | ||
| } | ||
| }); | ||
| }); | ||
| return ids; | ||
| }, [projectIds, workspacesByProjectId, projectNavigationSidebarFilter, expandedProjectAndWorkspaceIds]); |
Comment on lines
+45
to
+49
| return { | ||
| key: user.acct, | ||
| alt: user.firstName || user.lastName ? `${user.firstName} ${user.lastName}` : user.acct, | ||
| src: user.avatar, | ||
| }; |
| <span className="min-w-0 flex-1 truncate text-base text-[rgb(var(--color-font-rgb),0.8)]">{projectName}</span> | ||
| </div> | ||
| {presence.length > 0 && <AvatarGroup size="small" maxAvatars={3} items={presence} />} | ||
| {projectPresence.length > 0 && <AvatarGroup size="small" maxAvatars={3} items={projectPresence} />}{' '} |
Comment on lines
+103
to
+111
| organizationIdsToRevalidate.forEach(organizationId => | ||
| queryClient.invalidateQueries({ queryKey: projectKeys.details(organizationId) }), | ||
| ); | ||
| projectIdsToRevalidate.forEach(projectId => | ||
| queryClient.invalidateQueries({ queryKey: workspaceKeys.details(projectId) }), | ||
| ); | ||
| workspaceIdsToRevalidate.forEach(workspaceId => | ||
| queryClient.invalidateQueries({ queryKey: workspaceChildrenKeys.details(workspaceId) }), | ||
| ); |
remove workspaceCount from rootLoaderData move unrelevant loaders out add query context adapt tanstack query fix som issues add new ways to load data initial changes clean code
97892c4 to
62b7fb7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes:
This PR adds TanStack Query as a shared in-memory cache over the local NeDB, hosting all the necessary data for the new sidebar
Cache layer
insomnia-query-client.tsx: Single shared dbQueryClient + provider, mounted in organization.tsx.db-changes-sync.ts: Bridges window.main.on('db.changes') to the cache. Registered once at the provider level so it survives sidebar unmount.projects.ts, workspaces.ts, workspace-children.ts: query hooks + hierarchical keysConsumers migrated to the shared cache