Skip to content

Spike: Add a client cache layer for new sidebar data using tanstack#10134

Draft
cwangsmv wants to merge 2 commits into
developfrom
fix/new-sidebar-perf-tanstack
Draft

Spike: Add a client cache layer for new sidebar data using tanstack#10134
cwangsmv wants to merge 2 commits into
developfrom
fix/new-sidebar-perf-tanstack

Conversation

@cwangsmv

@cwangsmv cwangsmv commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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 keys
  • Consumers migrated to the shared cache

    • Sidebar reads projects/workspaces/collection children from the cache
    • Project index page (…project.$projectId._index.tsx) reads the project list and local files from the cache instead of getAllLocalFiles

Copilot AI review requested due to automatic review settings June 22, 2026 09:45
@cwangsmv cwangsmv marked this pull request as draft June 22, 2026 09:45
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown

✅ Circular References Report

Generated at: 2026-06-23T02:52:58.473Z
Status: ✅ NO CHANGE

Summary

Metric Base (develop) PR Change
Total Circular References 9 9 0 (0.00%)
Click to view all circular references in PR (9)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia/src/main/prompt-bridge.ts -> insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.ts
insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.ts
insomnia/src/network/network.ts -> insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts
insomnia/src/ui/components/settings/import-export.tsx -> insomnia/src/ui/components/modals/export-requests-modal.tsx
insomnia/src/ui/components/tabs/tab-list.tsx -> insomnia/src/ui/components/tabs/tab.tsx
insomnia/src/ui/components/templating/tag-editor-arg-sub-form.tsx -> insomnia/src/ui/components/templating/external-vault/external-vault-form.tsx
insomnia/src/ui/components/viewers/response-viewer.tsx -> insomnia/src/ui/components/viewers/response-multipart-viewer.tsx
Click to view all circular references in base branch (9)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia/src/main/prompt-bridge.ts -> insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.ts
insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.ts
insomnia/src/network/network.ts -> insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts
insomnia/src/ui/components/settings/import-export.tsx -> insomnia/src/ui/components/modals/export-requests-modal.tsx
insomnia/src/ui/components/tabs/tab-list.tsx -> insomnia/src/ui/components/tabs/tab.tsx
insomnia/src/ui/components/templating/tag-editor-arg-sub-form.tsx -> insomnia/src/ui/components/templating/external-vault/external-vault-form.tsx
insomnia/src/ui/components/viewers/response-viewer.tsx -> insomnia/src/ui/components/viewers/response-multipart-viewer.tsx

Analysis

No Change: This PR does not introduce or remove any circular references.


This report was generated automatically by comparing against the develop branch.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a db.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) }),
);
cwangsmv added 2 commits June 23, 2026 10:47
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
@cwangsmv cwangsmv force-pushed the fix/new-sidebar-perf-tanstack branch from 97892c4 to 62b7fb7 Compare June 23, 2026 02:47
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