Fix setState-in-render warning from convo cache subscription (#10934)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-06-24 19:37:57 +03:00
committed by GitHub
parent 0674626f3c
commit 2843374ef8
+6
View File
@@ -132,6 +132,12 @@ export function ConvoProvider({
useEffect(() => {
const [root, id] = getConvoKey(convoId)
return queryClient.getQueryCache().subscribe(event => {
// Only react to data updates. Other event types (e.g. `added`) can be
// emitted synchronously while another component reads this same query
// during its render (React Query builds the query in `getOptimisticResult`),
// and committing to the convo store then would set state on this provider
// mid-render of that component.
if (event.type !== 'updated') return
const queryKey = event.query.queryKey as string[]
if (queryKey[0] === root && queryKey[1] === id) {
const data = event.query.state.data as