Skip to content

Commit d1a7742

Browse files
authored
fix: avoid multiple rerenders when tags is an array
1 parent 3157b65 commit d1a7742

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/react-hooks/src/hooks/useRealtime.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ export function useRealtimeRunsWithTag<TTask extends AnyTask>(
428428

429429
const apiClient = useApiClient(options);
430430

431+
const stableTag = Array.isArray(tag)
432+
? JSON.stringify([...tag].sort())
433+
: tag;
431434
const triggerRequest = useCallback(async () => {
432435
try {
433436
if (!apiClient) {
@@ -459,7 +462,7 @@ export function useRealtimeRunsWithTag<TTask extends AnyTask>(
459462
abortControllerRef.current = null;
460463
}
461464
}
462-
}, [tag, mutateRuns, runsRef, abortControllerRef, apiClient, setError]);
465+
}, [stableTag, mutateRuns, runsRef, abortControllerRef, apiClient, setError]);
463466

464467
useEffect(() => {
465468
if (typeof options?.enabled === "boolean" && !options.enabled) {
@@ -471,7 +474,7 @@ export function useRealtimeRunsWithTag<TTask extends AnyTask>(
471474
return () => {
472475
stop();
473476
};
474-
}, [tag, stop, options?.enabled]);
477+
}, [stableTag, stop, options?.enabled]);
475478

476479
return { runs: runs ?? [], error, stop };
477480
}

0 commit comments

Comments
 (0)