Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/react-hooks/src/hooks/useRealtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ export function useRealtimeRun<TTask extends AnyTask>(
const hasCalledOnCompleteRef = useRef(false);

// Effect to handle onComplete callback
// Only call onComplete when the run has actually finished (has finishedAt),
// not just when the subscription stream ends (which can happen due to network issues)
useEffect(() => {
if (isComplete && run && options?.onComplete && !hasCalledOnCompleteRef.current) {
if (isComplete && run?.finishedAt && options?.onComplete && !hasCalledOnCompleteRef.current) {
options.onComplete(run, error);
hasCalledOnCompleteRef.current = true;
}
Expand Down Expand Up @@ -313,8 +315,10 @@ export function useRealtimeRunWithStreams<
const hasCalledOnCompleteRef = useRef(false);

// Effect to handle onComplete callback
// Only call onComplete when the run has actually finished (has finishedAt),
// not just when the subscription stream ends (which can happen due to network issues)
useEffect(() => {
if (isComplete && run && options?.onComplete && !hasCalledOnCompleteRef.current) {
if (isComplete && run?.finishedAt && options?.onComplete && !hasCalledOnCompleteRef.current) {
options.onComplete(run, error);
hasCalledOnCompleteRef.current = true;
}
Expand Down