Skip to content

Commit 14f9fcb

Browse files
ouiliameclaude
andcommitted
docs: send Ask AI locale per-message to avoid stale transport
useChat keeps the first transport, so the locale baked into it went stale after a language switch (retrieval stuck on the old locale). Send locale per-message instead; transport is now stable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c311ea8 commit 14f9fcb

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

apps/docs/components/ai/ask-ai.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ export function AskAI({ locale }: AskAIProps) {
5050
const [input, setInput] = useState('')
5151
const scrollRef = useRef<HTMLDivElement>(null)
5252

53-
const transport = useMemo(
54-
() => new DefaultChatTransport({ api: '/api/chat', body: { locale } }),
55-
[locale]
56-
)
53+
// Stable transport; the locale is sent per-message (below) so it stays current
54+
// after a language switch instead of being frozen into the transport.
55+
const transport = useMemo(() => new DefaultChatTransport({ api: '/api/chat' }), [])
5756

5857
const { messages, sendMessage, status, stop, error } = useChat({ transport })
5958

@@ -74,7 +73,7 @@ export function AskAI({ locale }: AskAIProps) {
7473
event.preventDefault()
7574
const text = input.trim()
7675
if (!text || isBusy) return
77-
sendMessage({ text })
76+
sendMessage({ text }, { body: { locale } })
7877
setInput('')
7978
}
8079

0 commit comments

Comments
 (0)