{{ message }}
Repository navigation
fix(query-core): re-attach MutationObserver to its in-flight mutation on resubscribe - #11217
Closed
iamshahid1997 wants to merge 1 commit into
Closed
iamshahid1997 wants to merge 1 commit into
iamshahid1997 wants to merge 1 commit into
Conversation
… on resubscribe When the last listener unsubscribes, onUnsubscribe() removes the observer from its current mutation, but resubscribing never added it back. If React tore down and re-established the subscription while a mutation was in flight (StrictMode, <Activity> hide/show, re-suspending boundaries), the mutation settled against an empty observer list and the observer kept serving its frozen 'pending' snapshot forever. Mirror QueryObserver.onSubscribe(): when the first listener subscribes, re-attach to the current mutation and refresh the result in case the mutation settled while detached. Fixes TanStack#11171
Contributor
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #11171
Problem
When the last listener unsubscribes,
MutationObserver.onUnsubscribe()removes the observer from its current mutation — but resubscribing never adds it back. React legitimately tears down and re-establishes the store subscription of a mounted component that keeps its state (<Activity mode="hidden">, re-suspending<Suspense>boundaries, StrictMode in dev).If that happens while a mutation is in flight, the mutation settles against an empty observer list, and the observer keeps serving its frozen
pendingsnapshot fromgetCurrentResult()forever:isPendingstaystrue→ submit buttons usingdisabled={isPending}stay disabled until remountmutate(vars, { onSuccess })never fireMutationCacheshowsuccesswhile the hook showspendingFix
Mirror
QueryObserver.onSubscribe(): when the first listener subscribes, re-attach the observer to its current mutation (Mutation.addObserveris already idempotent) and refresh the result snapshot in case the mutation settled while detached.Tests
Two regression tests in
mutationObserver.test.tsx, drivingsubscribe/unsubscribethe wayuseSyncExternalStoredoes:successand notifies the new listenerBoth fail on
mainand pass with the fix. Fullquery-core(627) andreact-query(577) suites pass.Summary by CodeRabbit
Bug Fixes
Tests