fix (ai-sdk/vue): status reactivity#6234
Merged
nicoalbanese merged 5 commits intomainfrom May 9, 2025
Merged
Conversation
Collaborator
|
Can you add tests that reproduce the bug? |
|
@nicoalbanese thanks for the prompt action! I'm wondering - shouldn't the https://chatgpt.com/share/681c77c5-f7c0-800d-b23d-0d0d1f5155ec // use-chat.ts
import { ref, Ref } from 'vue'
type Status = 'submitted' | 'streaming' | 'ready' | 'error'
// 1. A module‐scoped map from chatId → status ref
const statusMap = new Map<string, Ref<Status>>()
function getStatusRef(chatId: string): Ref<Status> {
if (!statusMap.has(chatId)) {
// initialize to “ready” the first time we see this chatId
statusMap.set(chatId, ref<Status>('ready'))
}
return statusMap.get(chatId)!
}
export function useChat({ chatId, ... }) {
// ... your existing messages, input, append, etc.
// 2. grab the per‐chat ref
const status = getStatusRef(chatId)
// 3. your “mutateStatus” shim from before
const mutateStatus = (
updater: Status | ((current: Status) => Status)
): Promise<Status> => {
status.value =
typeof updater === 'function'
? (updater as (s: Status) => Status)(status.value)
: updater
return Promise.resolve(status.value)
... |
|
@nicoalbanese I'm not use if my previous suggestion (dynamically creating multiple Instead of creating multiple import { reactive, toRef } from 'vue'
const statusState = reactive<Record<string, Status>>({})
function getStatusRef(chatId: string) {
if (!(chatId in statusState)) {
statusState[chatId] = 'ready'
}
// toRef makes a ref view into a property of a reactive object
return toRef(statusState, chatId)
} |
Collaborator
Author
|
hey @pavelsvitek - thanks for the help here! Had a working solution but took a little bit to get a good test written to repro. Should be good now! |
lgrammel
approved these changes
May 9, 2025
lgrammel
pushed a commit
that referenced
this pull request
May 10, 2025
## Background Bug with Vue that led to status not updating when tab was changed. ## Summary Changes status from using SWR to using Vue ref.
lgrammel
added a commit
that referenced
this pull request
May 10, 2025
jacobkerber
pushed a commit
to jacobkerber/ai
that referenced
this pull request
Jul 15, 2025
## Background Bug with Vue that led to status not updating when tab was changed. ## Summary Changes status from using SWR to using Vue ref.
jacobkerber
pushed a commit
to jacobkerber/ai
that referenced
this pull request
Jul 15, 2025
Bug with Vue that led to status not updating when tab was changed. Changes status from using SWR to using Vue ref.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Bug with Vue that led to status not updating when tab was changed.
Summary
Changes status from using SWR to using Vue ref.
Verification
Tested locally.
Tasks
pnpm changesetin the project root)Related Issues
Fixes #6110.