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