-
Notifications
You must be signed in to change notification settings - Fork 62
fix: refresh renderer stores after workspace change #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| import { useState, useEffect, useCallback } from 'react'; | ||
| import { useTaskStore } from '../../../platform'; | ||
| import { useMessageStore } from '../../../platform'; | ||
| import { useDashboardStore } from '@/stores/dashboardStore'; | ||
| import { useUsageStore } from '@/stores/usageStore'; | ||
| import { useApprovalStore } from '@/stores/approvalStore'; | ||
| import { MonitorDot, Zap, FolderOpen, Loader2, ExternalLink } from 'lucide-react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { toast } from '@/lib/toast'; | ||
|
|
@@ -64,6 +69,26 @@ export default function SystemSection() { | |
| [quickLaunchShortcut, t], | ||
| ); | ||
|
|
||
| // When main process signals workspace changed, clear and re-hydrate stores | ||
| useEffect(() => { | ||
| return window.clawwork.onWorkspaceChanged(async () => { | ||
| // Clear task store and re-hydrate from new DB | ||
| useTaskStore.setState({ tasks: [], activeTaskId: null, hydrated: false }); | ||
| useTaskStore.getState().hydrate(); | ||
|
|
||
| // Clear message store | ||
| useMessageStore.setState({ messagesByTask: {}, activeTurnBySession: {}, processingBySession: new Set() }); | ||
|
|
||
| // Clear dashboard, usage, and approval caches | ||
| useDashboardStore.getState().clear(); | ||
| useUsageStore.getState().clear(); | ||
| useApprovalStore.getState().clear(); | ||
|
|
||
| // Refresh settings to pick up new workspace config | ||
| await refreshSettings().catch(() => {}); | ||
| }); | ||
| }, [refreshSettings]); | ||
|
Comment on lines
+73
to
+90
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Consider moving this subscription to a global location (e.g., a root layout component or a dedicated initialization hook) to ensure the application state is consistently updated across all windows and views. Once moved, the manual References
|
||
|
|
||
| const handleChangeWorkspace = useCallback(async () => { | ||
| let selected: string | null = null; | ||
| try { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
BrowserWindow.getAllWindows()[0]is unreliable as it only targets the first window found by the runtime. In a multi-window environment (e.g., if the user has detached chat windows or multiple instances), other windows will not receive theworkspace:changedevent and will continue to display stale data from the previous workspace. It is better to broadcast the event to all open windows.