chore: update

This commit is contained in:
Amiram_se 2026-10-10 23:50:33 +04:00
parent aec09a0ecd
commit 6319052cc1
1 changed files with 10 additions and 2 deletions

View File

@ -1,6 +1,6 @@
'use client';
import type { QueryClient } from '@tanstack/react-query';
import { notifyManager, type QueryClient } from '@tanstack/react-query';
import { useEffect, useState } from 'react';
import { SLOW_READ_MS } from '../constants';
@ -18,6 +18,7 @@ export function useSlowReads(queryClient: QueryClient): boolean {
// When each first read still loading started, by query.
const started = new Map<string, number>();
let timer: ReturnType<typeof setTimeout> | undefined;
let active = true;
const check = () => {
clearTimeout(timer);
@ -43,9 +44,16 @@ export function useSlowReads(queryClient: QueryClient): boolean {
if (wait > 0) timer = setTimeout(check, wait);
};
const unsubscribe = cache.subscribe(check);
// The cache notifies while a child's useQuery builds its query mid-render; defer so this
// component's setState never lands inside another component's render.
const unsubscribe = cache.subscribe(() =>
notifyManager.schedule(() => {
if (active) check();
}),
);
check();
return () => {
active = false;
unsubscribe();
clearTimeout(timer);
};