From e505ef136bbd1ed5d3f4749b1d9249fbf1d9a79e Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 17 Jun 2026 14:35:12 +0300 Subject: [PATCH] fix setState-in-render warning from convo cache subscription ConvoProvider's query cache subscription mutated the convo store synchronously. When the conversation settings screen (stacked above the still-mounted conversation screen) renders and reads the same convo query, React Query emits a synchronous `added` cache event during render, firing the subscription and setting state on the underlying ConvoProvider. Only react to `updated` events, which fire on actual data writes and preserve the real sync behavior. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/state/messages/convo/index.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/state/messages/convo/index.tsx b/src/state/messages/convo/index.tsx index a78ea1a038..69ad1e237c 100644 --- a/src/state/messages/convo/index.tsx +++ b/src/state/messages/convo/index.tsx @@ -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