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) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user