fix(documents): keep feature-flags query out of realtime invalidation

The feature-flags query previously sat at ['documents', 'feature-flags'],
which the hub's useRealtimeInvalidation([['documents']]) registration
matched via TanStack's default prefix matching. Every document socket
event refetched the flag, silently defeating the 5-minute staleTime.
Move the key to ['documents-feature-flags'] so it sits outside the
prefix; document events no longer trigger a flag refetch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-10 12:34:51 +02:00
parent f8fcb8d8ad
commit 8e06d4549d

View File

@@ -120,11 +120,11 @@ export function DocumentsHub({ portSlug, initialTab = 'all' }: DocumentsHubProps
});
const { data: flagsResp } = useQuery<{ data: { showExpiredTab: boolean } }>({
queryKey: ['documents', 'feature-flags'],
queryKey: ['documents-feature-flags'],
queryFn: () => apiFetch('/api/v1/documents/feature-flags'),
staleTime: 5 * 60 * 1000,
});
const showExpiredTab = flagsResp?.data.showExpiredTab ?? true;
const showExpiredTab = flagsResp?.data?.showExpiredTab ?? true;
useRealtimeInvalidation({
'document:created': [['documents']],
@@ -282,16 +282,18 @@ export function DocumentsHub({ portSlug, initialTab = 'all' }: DocumentsHubProps
}}
>
<TabsList>
{documentsHubTabs.filter((t) => t !== 'expired' || showExpiredTab).map((t) => (
<TabsTrigger key={t} value={t}>
{TAB_LABELS[t]}
{t !== 'all' && counts[t] > 0 ? (
<span className="ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-[0.65rem] text-muted-foreground">
{counts[t]}
</span>
) : null}
</TabsTrigger>
))}
{documentsHubTabs
.filter((t) => t !== 'expired' || showExpiredTab)
.map((t) => (
<TabsTrigger key={t} value={t}>
{TAB_LABELS[t]}
{t !== 'all' && counts[t] > 0 ? (
<span className="ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-[0.65rem] text-muted-foreground">
{counts[t]}
</span>
) : null}
</TabsTrigger>
))}
</TabsList>
</Tabs>