Skip to main content

The Problem

Traceo’s workspace switcher dropdown rendered correctly. Users could click to select a different workspace. The UI updated the selection indicator. But all data — requirements, diagrams, sessions — remained from the original workspace. Page refresh reverted even the UI selection.

The Root Cause

The switcher updated activeWorkspaceId in a React context (client-side only). Every API route independently read user.workspaceId from the database. The context state was never persisted anywhere — not to the database, not to a cookie, not to localStorage. The frontend and backend had completely decoupled notions of “active workspace”.

The Fix

Added a PATCH /api/workspaces endpoint that updates user.workspaceId in the database. The frontend now calls this endpoint before updating local state and refreshing. Updated GET /api/workspaces to return all workspaces with an is_active flag so the dropdown populates correctly.

The Takeaway

When all API routes derive context from the database (not from request headers or cookies), any “switching” feature must write to the database. Client-side state management creates a convincing UI illusion but delivers zero functional change. Always trace the data path: if the API reads from source X, the switcher must write to source X.