fix(solid-query): scope useMutation's cache subscription to the flight - #11325
Conversation
The hook subscribed to the mutation cache at mount with a bare reactive client() read — tripping Solid's STRICT_READ_UNTRACKED dev diagnostic (reported by @brenelz in TanStack#11324) — and held that subscription for its whole life even though the listener only matters between mutate and settle. Rather than untracking the read, remove it: subscribe inside run(), against the same client the mutation is built on, and unsubscribe at the settle points (plus onCleanup for unmount mid-flight). By construction: no reactive read at setup (nothing to untrack), the listener and the mutation can never sit on different clients across a QueryClient swap, and an idle useMutation holds no cache subscription — mutation-cache events no longer fan out to every mounted hook. Includes the TanStack#11324 regression test (no strict-read diagnostic on mount) plus a listener-count test pinning the idle/flight/settled subscription lifecycle. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit afe2bf1
☁️ Nx Cloud last updated this comment at |
Summary
Alternative to #11324 — thanks @brenelz for catching the
STRICT_READ_UNTRACKEDdiagnostic. Rather than untracking the mount-timeclient()read, this removes it: the diagnostic was pointing at a subscription that shouldn't exist at mount at all.useMutationsubscribed to the mutation cache at setup and held that subscription for the hook's whole life, but the listener only does anything between mutate and settle (activeMutationis null otherwise). The subscription now starts insiderun, created against the same client the mutation is built on, and ends at the settle points (plusonCleanupfor unmount mid-flight; a rapid re-mutate replaces the previous flight's listener).What this buys over
untrack:mutatebuilt against the live one — aQueryClientswap could leave the listener on the old cache, silently dropping flight events.useMutationused to hear every mutation-cache event forever just to filter it out; now cache events only fan out to hooks actually in flight.Tests
Made with Cursor