Skip to content

fix(workspaces): persist visit recency server-side so sidebar order is stable on refresh - #8284

Merged
waleedlatif1 merged 5 commits into
stagingfrom
fix/sidebar-workspace-order-flash
Sep 25, 2026
Merged

waleedlatif1 merged 5 commits into
stagingfrom
fix/sidebar-workspace-order-flash

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Workspace visit order lived only in localStorage, so the server rendered the sidebar newest-first and the client re-sorted after hydration — non-pinned workspaces reshuffled on every refresh (pins were already server-side, so they stayed put)
  • New workspace_visit table (one row per user + workspace, last visit time); POST /api/workspaces/[id]/visit records a visit through a session-only workspaces.visits.record operation, replacing the settings write the sidebar made on every visit
  • Visits are stamped with the database clock and sent one at a time (mutation scope), so rapid switching always leaves the last-opened workspace newest
  • GET /api/workspaces returns workspaces most recently visited first (then newest first) and derives lastActiveWorkspaceId from the latest visit, falling back to the legacy settings column
  • Sidebar switcher and org sidebar read one order from the list query (pins lifted to the top in a select), so server render and hydration always agree and the order follows the user across devices
  • Visiting moves the workspace to the front of the cached list immediately; the list reconciles after the last queued visit settles
  • Removed WorkspaceRecencyStorage and useWorkspaceOrder
  • Anything taking workspaces[0] (the /workspace redirect fallback, orphaned-workflow repair) now gets the most recently visited workspace instead of the newest

Follow-up (after this is fully deployed): drop settings.last_active_workspace_id and its settings API fields, once the settings full-row inserts exclude it.

Type of Change

  • Bug fix

Testing

  • Hydration test asserts server render matches the final order and hydration changes zero DOM nodes
  • Unit tests for the visit use case (role, principal kinds, concealment, not found), route (401/200/404 parity), repository, ordering, and the visit mutation (optimistic reorder, serialization, last-settle reconcile)
  • lint, type-check, check:audits (49), check:api-validation:strict, check:migrations, docs-manifest:check pass

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)

🤖 Generated with Claude Code

@vercel

vercel Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 25, 2026 1:16am UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 24 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/workspaces/visits.ts Outdated
Comment thread apps/sim/lib/workspaces/visits.ts Outdated
Comment thread packages/db/migrations/0383_workspace_visit.sql
@greptile-apps

greptile-apps Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Adds database migration and shifts workspace ordering to server-side.

The PR appears safe to merge based on the changes reviewed.

Summary

The PR persists workspace visit recency server-side and uses the resulting order for sidebars and workspace redirects.

  • Adds a visit endpoint, database table, and optimistic list update.
  • Replaces browser-only recency ordering and adds ordering and hydration tests.
  • The changes since the previous review address the remaining comment-format finding. All previous threads are resolved.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Open workspace] --> B[Record visit]
  B --> C[workspace_visit]
  C --> D[Workspace list in visit order]
  D --> E[Sidebar and redirects]
Loading

Reviews (5) · Last reviewed commit: "chore(workspaces): write the permission-..."

Comment thread apps/sim/lib/workspaces/visits.ts Outdated
Comment thread apps/sim/hooks/queries/workspace.ts Outdated
Comment thread apps/sim/lib/workspaces/visits.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 24 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 24 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

Comment thread apps/sim/lib/workspaces/application/record-workspace-visit.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 24 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 0be1f38 into staging Sep 25, 2026
34 checks passed

This branch was previously deployed

1 inactive deployment
Preview — 42fad405 Deployed Sep 25, 2026 by vercel[bot]
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