Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(vue) useChat not responsive to changes in the conversation ID #4900

Open
pqnet opened this issue Feb 15, 2025 · 0 comments
Open

(vue) useChat not responsive to changes in the conversation ID #4900

pqnet opened this issue Feb 15, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@pqnet
Copy link

pqnet commented Feb 15, 2025

Description

In Vue it is impossible to change id for useChat component based on a prop value (or a route parameter), since properties are reactive and id value must be fixed at setup stage.

Code example

// App.vue
<script setup lang="ts">
import Chat from "./components/Chat.vue";
import { ref } from "vue";
const chatId = ref("123");
</script>

<template>
  <input v-model="chatId" type="number" />
  <p>
    {{ chatId }}
  </p>
  <Chat :chatId />
</template>

// Chat.vue
<template>
  <p>{{ chatId }}</p>
  <p>{{ id }}</p>
</template>
<script setup lang="ts">
import { useChat } from "@ai-sdk/vue";
const props = defineProps<{ chatId: string }>();
const { id } = useChat({ id: props.chatId });
</script>

AI provider

No response

Additional context

Differently from React, the setup function is not re-executed every time props change, but rather the properties themselves are reactive.

The standard pattern for Vue composables that have to react to their input is to accept a MaybeRef<T> as a parameter and use computed/watch/watchEffect to handle changes to the parameter, rather than rely on useChat being invoked again when they change.

@pqnet pqnet added the bug Something isn't working label Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant