Skip to content

Commit f7240a9

Browse files
authored
fix(react): prevent infinite useEffect when passing an array of tags to useRealtimeRunsWithTag (#2705)
1 parent 6e47377 commit f7240a9

File tree

32 files changed

+1865
-108
lines changed

32 files changed

+1865
-108
lines changed

.changeset/late-kings-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/react-hooks": patch
3+
---
4+
5+
fix: prevent infinite useEffect when passing an array of tags to useRealtimeRunsWithTag

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ export function useRealtimeRunsWithTag<TTask extends AnyTask>(
404404
tag: string | string[],
405405
options?: UseRealtimeRunsWithTagOptions
406406
): UseRealtimeRunsInstance<TTask> {
407+
const normalizedTag = (Array.isArray(tag) ? tag : [tag]).join("-");
408+
407409
const hookId = useId();
408410
const idKey = options?.id ?? hookId;
409411

@@ -466,7 +468,7 @@ export function useRealtimeRunsWithTag<TTask extends AnyTask>(
466468
abortControllerRef.current = null;
467469
}
468470
}
469-
}, [tag, mutateRuns, runsRef, abortControllerRef, apiClient, setError]);
471+
}, [normalizedTag, mutateRuns, runsRef, abortControllerRef, apiClient, setError]);
470472

471473
useEffect(() => {
472474
if (typeof options?.enabled === "boolean" && !options.enabled) {
@@ -478,7 +480,7 @@ export function useRealtimeRunsWithTag<TTask extends AnyTask>(
478480
return () => {
479481
stop();
480482
};
481-
}, [tag, stop, options?.enabled]);
483+
}, [normalizedTag, stop, options?.enabled]);
482484

483485
return { runs: runs ?? [], error, stop };
484486
}

0 commit comments

Comments
 (0)