fix: wait for zustand hydration before workspace initialization

Fix blank page on first load via `ccw view` by waiting for zustand persist
hydration to complete before initializing workspace.

- Add _hasHydrated state tracking in workflowStore
- Add setHasHydrated action to mark hydration complete
- Update AppShell to wait for hydration before calling switchWorkspace
- Ensures projectPath is properly restored from localStorage before queries execute
This commit is contained in:
catlog22
2026-03-04 10:56:07 +08:00
parent 26bda9c634
commit 5e96722c09
3 changed files with 22 additions and 1 deletions

View File

@@ -40,15 +40,23 @@ export function AppShell({
// Workspace initialization from URL query parameter
const switchWorkspace = useWorkflowStore((state) => state.switchWorkspace);
const projectPath = useWorkflowStore((state) => state.projectPath);
const hasHydrated = useWorkflowStore((state) => state._hasHydrated);
const location = useLocation();
// Immersive mode (fullscreen) - hide chrome
const isImmersiveMode = useAppStore(selectIsImmersiveMode);
// Workspace initialization logic (URL > localStorage)
// Wait for zustand persist hydration to complete before initializing
const [isWorkspaceInitialized, setWorkspaceInitialized] = useState(false);
useEffect(() => {
// Wait for hydration to complete before initializing workspace
// This ensures projectPath is properly restored from localStorage
if (!hasHydrated) {
return;
}
// This effect should only run once to decide the initial workspace.
if (isWorkspaceInitialized) {
return;
@@ -76,7 +84,7 @@ export function AppShell({
// Mark as initialized regardless of whether a path was found.
setWorkspaceInitialized(true);
}, [isWorkspaceInitialized, projectPath, location.search, switchWorkspace]);
}, [hasHydrated, isWorkspaceInitialized, projectPath, location.search, switchWorkspace]);
// Sidebar collapse state default to collapsed (hidden)
const [sidebarCollapsed, setSidebarCollapsed] = useState(() => {