Skip to content

fix(lit-query): propagate mutation state generics - #11355

Open
Osraka wants to merge 3 commits into
TanStack:mainfrom
Osraka:osraka/fix-lit-mutation-state-generics
Open

Osraka wants to merge 3 commits into
TanStack:mainfrom
Osraka:osraka/fix-lit-mutation-state-generics

Conversation

@Osraka

@Osraka Osraka commented Sep 1, 2026 •

Copy link
Copy Markdown

🎯 Changes

@tanstack/lit-query did not receive the useMutationState generic inference added to the other framework adapters in #10373. As a result, a selector with an explicitly typed MutationState<TData, TError, TVariables> still saw Mutation<unknown, Error, unknown, unknown>.

This PR:

  • derives the selector's Mutation type from the selected MutationState result
  • adds a focused compile-time regression test
  • keeps runtime filtering/subscription behavior and scalar selector inference unchanged

The regression test fails on current main and passes with this change.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed TypeScript inference in useMutationState so the select callback receives the mutation’s specific data, error, and variables types.

@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: TanStack/query/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e68af60c-461f-4af0-b995-e11c6595ebb2
📥 Commits

Reviewing files that changed from the base of the PR and between ed72ceb and ba15beb.

📒 Files selected for processing: 2
  • packages/lit-query/src/__tests__/mutation-state-types.test.ts
  • packages/lit-query/src/useMutationState.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

useMutationState now infers a mutation type from its result type and passes it to the select callback. Type tests verify default and custom generic inference. A changeset records a patch release.

Changes: Lit mutation state generic propagation

Layer / File(s) Summary
Mutation type propagation
packages/lit-query/src/useMutationState.ts
MutationStateOptions, MutationStateController, and useMutationState now carry the inferred mutation type. The selector casts each cached mutation to that type before invoking it.
Type-level validation and release metadata
packages/lit-query/src/__tests__/mutation-state-types.test.ts, .changeset/lit-mutation-state-generics.md
Type tests cover default state types, selected-value inference, optional error-message selection, and custom mutation generics. The changeset declares a patch release for @tanstack/lit-query.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: chughgaurav

Merge Risk: ⚪ Minimal · up to ba15b

The generic inference change and its regression tests are ready to merge after normal checks.

Security architecture risk: 🔵 Low · up to 8663c

The change gives selectors more specific mutation types without changing how mutations are selected or subscribed to at runtime. No new security exposure was identified, but the stronger type promise is not checked at runtime.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The type-only change does not expand executable access beyond the existing query-client mutation cache path; no new privileged sink is evident in the inspected entrypoint.

Trust Boundaries and Controls

  • observed — Mutation selection remains scoped to the supplied query client and optional caller-provided filters. The new generic type is not a runtime boundary or validation control.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: propagating mutation state generics in lit-query.
Description check Passed The description includes the required Changes, Checklist, and Release Impact sections. It explains the motivation, implementation, regression test, validation, and changeset. The AI contribution polic…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes the required Changes, Checklist, and Release Impact sections. It explains the motivation, implementation, regression test, validation, and changeset. The AI contribution policy checkbox wording differs slightly from the template, but the author confirms understanding of the code and AI-assisted changes.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Osraka
Osraka force-pushed the osraka/fix-lit-mutation-state-generics branch from 185d545 to 8663c5e Compare September 28, 2026 15:23
@Osraka

Osraka commented Sep 28, 2026 •

Copy link
Copy Markdown
Author

Refreshed this against current main and resolved the Lit test-directory/host changes without changing the scope of the fix. The regression test now uses the repository's current LitElement test pattern. Local validation: tsc --noEmit, the focused Vitest test, the full Lit suite (109 tests, 10 files), ESLint (0 errors; warnings are in unchanged files), and Prettier check. GitHub checks are rerunning on the new head.

@changeset-bot

changeset-bot Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ba15beb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/lit-query Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@nx-cloud

nx-cloud Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit ed72ceb

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ❌ Failed 1m 4s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 37s View ↗

☁️ Nx Cloud last updated this comment at 2026-10-17 16:56:01 UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 17, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@11355

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@11355

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@11355

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@11355

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@11355

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@11355

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@11355

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@11355

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@11355

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@11355

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@11355

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@11355

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@11355

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@11355

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@11355

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@11355

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@11355

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@11355

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@11355

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@11355

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@11355

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@11355

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@11355

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@11355

commit: ed72ceb

import { LitElement } from 'lit'
import { describe, expectTypeOf, it } from 'vitest'
import { useMutationState } from '../useMutationState.js'
import { generateElementName } from './test-utils.js'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file doesn’t exist

Suggested change
import { generateElementName } from './test-utils.js'
import { generateElementName } from './utils.js'

import type { Mutation, MutationState } from '@tanstack/query-core'

describe('useMutationState types', () => {
it('propagates typed mutation state generics to the select callback', () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need more tests please. This seems to fail now but worked before:

useMutationState(host, {
  select: (mutation) => mutation.state.error?.message,
})

please add at least the same test as the react adapter has, and construct the types in the same way because this works in the react version.

@Osraka

Osraka commented Oct 20, 2026

Copy link
Copy Markdown
Author

Addressed both review points in ba15beb: the type test now imports ./utils.js, and the default TResult uses MutationState so the core default error type is preserved. I added default-state and selected-status parity cases plus the exact mutation.state.error?.message case; the latter failed with TS2339 before the fix. Locally, all Lit type checks, 309 Vitest tests, formatting, and oxlint pass. I will check the new CI run.

@Osraka
Osraka requested a review from TkDodo October 20, 2026 17:03

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants