fix(web): prevent useWorkspaceId crash in AppSidebar before workspace hydration
AppSidebar renders outside the workspace guard in dashboard layout. On first login, workspace hasn't hydrated yet → useWorkspaceId() throws. Fix: read workspace?.id directly from store, use enabled guard on inbox query. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fe9479d6fc
commit
030627c8c5
1 changed files with 9 additions and 4 deletions
|
|
@ -44,8 +44,9 @@ import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip
|
|||
import { useAuthStore } from "@/features/auth";
|
||||
import { useWorkspaceStore } from "@/features/workspace";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useWorkspaceId } from "@core/hooks";
|
||||
import { inboxListOptions, deduplicateInboxItems } from "@core/inbox/queries";
|
||||
import { inboxKeys } from "@core/inbox/queries";
|
||||
import { deduplicateInboxItems } from "@core/inbox/queries";
|
||||
import { api } from "@/shared/api";
|
||||
import { useModalStore } from "@/features/modals";
|
||||
|
||||
const primaryNav = [
|
||||
|
|
@ -76,8 +77,12 @@ export function AppSidebar() {
|
|||
const workspaces = useWorkspaceStore((s) => s.workspaces);
|
||||
const switchWorkspace = useWorkspaceStore((s) => s.switchWorkspace);
|
||||
|
||||
const wsId = useWorkspaceId();
|
||||
const { data: inboxItems = [] } = useQuery(inboxListOptions(wsId));
|
||||
const wsId = workspace?.id;
|
||||
const { data: inboxItems = [] } = useQuery({
|
||||
queryKey: wsId ? inboxKeys.list(wsId) : ["inbox", "disabled"],
|
||||
queryFn: () => api.listInbox(),
|
||||
enabled: !!wsId,
|
||||
});
|
||||
const unreadCount = React.useMemo(
|
||||
() => deduplicateInboxItems(inboxItems).filter((i) => !i.read).length,
|
||||
[inboxItems],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue