Skip to content

Commit

Permalink
fix(core): use ref to store loading state (#436)
Browse files Browse the repository at this point in the history
discovered in #295, using `useSWRV` to track a loading state means we actually get a fetch to the loading API key. We can just use a vue `ref` to handle this state, however.
  • Loading branch information
danielroe committed Aug 11, 2023
1 parent a0ee4be commit 4ef8015
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/mighty-apricots-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

Prevent `isLoading` in vue integration from triggering extraneous network requests
5 changes: 4 additions & 1 deletion packages/core/vue/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ export function useChat({
)

const { data: isLoading, mutate: mutateLoading } = useSWRV<boolean>(
`${chatId}-loading`
`${chatId}-loading`,
null
)

isLoading.value ??= false

// Force the `data` to be `initialMessages` if it's `undefined`.
data.value ||= initialMessages

Expand Down

0 comments on commit 4ef8015

Please sign in to comment.