Fix: Solid query `useIsMutating` throwing an error and `useMutationState` infinite loop
- Fixes an infinite loop in
useMutationStatecaused by reading and writing toresultsin an effect. - Fixes
useIsMutatingthrowing areading properties of undefinederror caused by readingisMutatingofclientwhich could be undefined in the case of some SSR environments/setups. This fix also makes it consistent withuseMutationStatewhere the subscription is created inside of an effect
Summary by CodeRabbit
-
Bug Fixes
- More reliable mutation status updates that react correctly to changing inputs.
- Proper cleanup of subscriptions on component unmount or re-run, reducing potential leaks.
- Prevented stale data by resubscribing when relevant reactive sources change.
-
Performance
- Reduced unnecessary recalculations and renders by avoiding tracked reads during comparisons.
- More efficient equality checks to minimize redundant updates.
-
Refactor
- Improved reactivity management without altering the public API.
Walkthrough
The subscription to the mutation cache in useIsMutating was moved into a Solid createEffect with onCleanup for lifecycle management. In useMutationState, untrack was introduced to read the result signal untracked within the subscription callback, adjusting equality checks accordingly. Public APIs remain unchanged.
Changes
| Cohort / File(s) | Summary of edits |
|---|---|
Reactive subscription lifecycle updatepackages/solid-query/src/useIsMutating.ts |
Wrapped mutation cache subscription in Solid createEffect; added onCleanup to dispose subscriptions; effect depends on mutationCache(), client(), and filters?.() to resubscribe on changes; imported createEffect. |
Untracked result handling in mutation statepackages/solid-query/src/useMutationState.ts |
Imported untrack; inside subscription callback, read result via untrack(result) to avoid reactive tracking; used this untracked value in replaceEqualDeep and equality check before setting nextResult. |
Sequence Diagram(s)
sequenceDiagram
autonumber
participant C as Component
participant U as useIsMutating
participant E as Solid createEffect
participant MC as MutationCache
participant CL as onCleanup
C->>U: call useIsMutating(filters)
U->>E: createEffect(() => { ... })
E->>MC: subscribe(onEvent)
Note over E,MC: Effect reads mutationCache(), client(), filters?.()
MC-->>E: mutation events
E->>U: set mutations count via client().isMutating(...)
CL-->>MC: unsubscribe on cleanup/re-run
Note over E: Re-runs and re-subscribes when dependencies change
sequenceDiagram
autonumber
participant MC as MutationCache
participant S as Subscription Callback
participant R as result signal
participant UT as untrack(...)
participant EQ as replaceEqualDeep + compare
participant ST as setState
MC-->>S: notify on mutation change
S->>UT: _result = untrack(R)
S->>EQ: next = replaceEqualDeep(prev, _result)
alt _result !== next
S->>ST: update state to next
else
S-->>S: no update
end
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
- TkDodo
Pre-merge checks (2 passed, 1 warning)
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title Check | ✅ Passed | The title concisely and accurately summarizes the PR’s primary intent by naming the two affected Solid Query hooks and the specific bugs being fixed, and it aligns with the PR description and file-level changes so a reviewer can quickly understand the main purpose. |
Poem
A whisker twitch, a subtle tweak—
Subscriptions nest, then softly sleep.
Untracked footsteps, quiet, neat,
Signals hum with lighter feet.
In Solid burrows, caches sing—
Hop hop! Another tidy spring. 🐇✨
[!TIP]
👮 Agentic pre-merge checks are now available in preview!
Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
- Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
- Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.
Please see the documentation for more information.
Example:
reviews: pre_merge_checks: custom_checks: - name: "Undocumented Breaking Changes" mode: "warning" instructions: | Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post.
✨ Finishing touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
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 @coderabbitai help to get the list of available commands and usage tips.
please add a test that fails on main but works with your changes. thanks 🙏
@ardeora FYI
⚠️ No Changeset found
Latest commit: a3feb81ca2302b630a9536a52f2c69d1ea7f3b33
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR