Skip to content

Commit

Permalink
fix (ai/react): useObject stop & isLoading reset at end of stream (#2126
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lgrammel committed Jun 27, 2024
1 parent 83204b7 commit 9b50003
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-dolphins-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ai-sdk/react': patch
---

fix (ai/react): useObject stop & isLoading reset at end of stream
8 changes: 5 additions & 3 deletions packages/react/src/use-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,17 @@ function useObject<RESULT, INPUT = any>({
mutate(currentObject);
}
},

close() {
setIsLoading(false);
abortControllerRef.current = null;
},
}),
);

setError(undefined);
} catch (error) {
setError(error);
} finally {
setIsLoading(false);
abortControllerRef.current = null;
}
};

Expand Down
6 changes: 4 additions & 2 deletions packages/react/src/use-object.ui.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ describe('text stream', () => {
streamController.enqueue('"Hello, world!"}');
streamController.close();

await screen.findByTestId('loading');
expect(screen.getByTestId('loading')).toHaveTextContent('false');
// wait for element "loading" to have text content "false":
await waitFor(() => {
expect(screen.getByTestId('loading')).toHaveTextContent('true');
});
});
});

Expand Down

0 comments on commit 9b50003

Please sign in to comment.