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:
@@ -132,6 +132,12 @@ export function ConvoProvider({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const [root, id] = getConvoKey(convoId)
|
const [root, id] = getConvoKey(convoId)
|
||||||
return queryClient.getQueryCache().subscribe(event => {
|
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[]
|
const queryKey = event.query.queryKey as string[]
|
||||||
if (queryKey[0] === root && queryKey[1] === id) {
|
if (queryKey[0] === root && queryKey[1] === id) {
|
||||||
const data = event.query.state.data as
|
const data = event.query.state.data as
|
||||||
|
|||||||
Reference in New Issue
Block a user