Skip to content

Commit fb77bb1

Browse files
authored
🤖 fix: workspace sidebar updates immediately on creation (#997)
The `useWorkspaceRecency` hook was subscribed to `states.subscribeAny`, but workspace recency is bumped via `derived.bump("recency")`. This caused a delay between workspace creation and the sidebar reflecting the new workspace. ## Root Cause When a workspace is created: 1. `addWorkspace` is called, which calls `this.derived.bump("recency")` (line 731) 2. `useWorkspaceRecency` was subscribed to `store.subscribe` which delegates to `states.subscribeAny` 3. Since recency is bumped on `derived`, not `states`, React wasn't notified of the change 4. The sidebar would only update when some other action triggered a `states` bump ## Fix 1. Added `subscribeDerived` method to `WorkspaceStore` that exposes `derived.subscribeAny` 2. Updated `useWorkspaceRecency` to use `subscribeDerived` instead of `subscribe` Now when `derived.bump("recency")` is called, the subscription fires immediately and React re-renders the sidebar with the new workspace. _Generated with `mux`_
1 parent 404b3e8 commit fb77bb1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/browser/stores/WorkspaceStore.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,12 @@ export class WorkspaceStore {
401401
*/
402402
subscribe = this.states.subscribeAny;
403403

404+
/**
405+
* Subscribe to derived state changes (recency, etc.).
406+
* Use for hooks that depend on derived.bump() rather than states.bump().
407+
*/
408+
subscribeDerived = this.derived.subscribeAny;
409+
404410
/**
405411
* Subscribe to changes for a specific workspace.
406412
* Only notified when this workspace's state changes.
@@ -1087,11 +1093,12 @@ export function useWorkspaceStoreRaw(): WorkspaceStore {
10871093

10881094
/**
10891095
* Hook to get workspace recency timestamps.
1096+
* Subscribes to derived state since recency is updated via derived.bump("recency").
10901097
*/
10911098
export function useWorkspaceRecency(): Record<string, number> {
10921099
const store = getStoreInstance();
10931100

1094-
return useSyncExternalStore(store.subscribe, () => store.getWorkspaceRecency());
1101+
return useSyncExternalStore(store.subscribeDerived, () => store.getWorkspaceRecency());
10951102
}
10961103

10971104
/**

0 commit comments

Comments
 (0)