Skip to content

improvement(sidebar): prefetch workspace list server-side so the switcher never flashes loading#5706

Merged
waleedlatif1 merged 1 commit into
stagingfrom
sidebar-workspace-prefetch
Jul 16, 2026
Merged

improvement(sidebar): prefetch workspace list server-side so the switcher never flashes loading#5706
waleedlatif1 merged 1 commit into
stagingfrom
sidebar-workspace-prefetch

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Prefetch the workspace list in the workspace layout alongside the existing sidebar prefetches (workflows, chats, folders, permissions), so the workspace switcher header no longer flashes a skeleton and the dropdown no longer shows "Loading workspaces..." on cold loads
  • Extract the read-only list assembly from GET /api/workspaces into listWorkspacesForViewer (lib/workspaces/list.ts); the route keeps its write paths (default-workspace creation, orphaned-workflow repair) and returns the same JSON, with the creation-policy/list/settings/invite-flag queries now fully parallelized
  • The prefetch parses the server payload through the route contract's response schema and the same shared normalizer the client hook uses, so the cached shape is guaranteed identical to a client fetch; an empty list throws so the prefetch caches nothing and the route's self-healing creation path still runs
  • Extract resolveInviteFlags into lib/workspaces/policy.ts (was duplicated between the list mapping and workspace creation), getActiveOrganizationId into lib/auth/session-response.ts (replaces three inline session casts), and normalizeWorkspace into hooks/queries/utils/workspace-list-query.ts (was triplicated across fetchers)
  • Dedupe the workspace avatar initial computation in the sidebar header into a module-scope helper

Type of Change

  • Improvement

Testing

Typecheck, lint, 212 tests across workspace lib/route/hooks/layout pass; check:api-validation, check:client-boundary, and check:react-query all green

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 16, 2026 8:27am

Request Review

@cursor

cursor Bot commented Jul 16, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Read-path refactor and SSR prefetch with explicit guards for empty lists and unchanged route write behavior; no auth or billing rule changes beyond consolidation.

Overview
Server-side workspace list prefetch hydrates workspaceKeys.list('active') in the workspace layout alongside existing sidebar prefetches, so the switcher header and dropdown avoid skeleton / "Loading workspaces..." on cold loads. Prefetch uses listWorkspacesForViewer, validates through the route contract schema, and shares normalizeWorkspacesResponse with the client hook; an empty list throws so nothing is cached and GET /api/workspaces can still run default-workspace creation.

Refactors: read-only list assembly moves to listWorkspacesForViewer (lib/workspaces/list.ts) while the route keeps writes (default workspace, orphaned-workflow repair). getActiveOrganizationId centralizes session org reads; resolveInviteFlags dedupes invite UI flags; workspace avatar initials use getWorkspaceInitial in the header.

Reviewed by Cursor Bugbot for commit 515ef19. Configure here.

Comment thread apps/sim/app/workspace/[workspaceId]/prefetch.ts
@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR prefetches workspace data during server rendering to prevent loading flashes in the workspace switcher. The main changes are:

  • Adds the workspace list to the sidebar prefetch and hydrates the shared query cache.
  • Extracts read-only workspace list assembly and invite-flag resolution into shared helpers.
  • Uses one response normalizer for server-prefetched and client-fetched workspace data.
  • Centralizes active organization ID extraction and workspace avatar initials.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The empty-list path still reaches the route that creates a default workspace.
  • The route retains its existing workflow repair behavior for client fetches.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/prefetch.ts Adds workspace-list prefetching under the same query key, schema, normalizer, and stale time used by the client.
apps/sim/app/api/workspaces/route.ts Delegates read-only response assembly while keeping workspace creation and workflow repair in the route.
apps/sim/lib/workspaces/list.ts Extracts workspace listing, role mapping, invite policy mapping, settings lookup, and creation policy assembly.
apps/sim/hooks/queries/utils/workspace-list-query.ts Defines shared workspace response normalization and the workspace-list stale time.
apps/sim/lib/workspaces/policy.ts Centralizes conversion from invite policy results to caller-facing invite flags.

Reviews (2): Last reviewed commit: "improvement(sidebar): prefetch workspace..." | Re-trigger Greptile

Comment thread apps/sim/app/workspace/[workspaceId]/prefetch.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ 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 515ef19. Configure here.

@waleedlatif1
waleedlatif1 merged commit 2ec72b6 into staging Jul 16, 2026
20 checks passed
@waleedlatif1
waleedlatif1 deleted the sidebar-workspace-prefetch branch July 16, 2026 08:42
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.

1 participant