Skip to content

Comments

feat(svelte-query): add 'mutationOptions'#10175

Open
sukvvon wants to merge 6 commits intoTanStack:mainfrom
sukvvon:feat/svelte-query-mutationOptions
Open

feat(svelte-query): add 'mutationOptions'#10175
sukvvon wants to merge 6 commits intoTanStack:mainfrom
sukvvon:feat/svelte-query-mutationOptions

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Feb 23, 2026

🎯 Changes

Add mutationOptions identity function to @tanstack/svelte-query for type-safe mutation configuration, matching the existing implementation in react-query and preact-query.

  • Add mutationOptions with two overloads (with/without mutationKey)
  • Add 13 type tests and 14 runtime tests
  • Add reference documentation

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 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

  • New Features

    • Added a new mutationOptions utility to svelte-query for configuring mutations.
  • Documentation

    • Added API reference and detailed docs for mutationOptions, including usage and signatures.
  • Tests

    • Added comprehensive runtime, component, and type-level tests covering mutationOptions behavior and integrations.
  • Chores

    • Recorded a minor version bump and updated the changelog for the feature release.

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2026

🦋 Changeset detected

Latest commit: 5048011

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

This PR includes changesets to release 3 packages
Name Type
@tanstack/svelte-query Minor
@tanstack/svelte-query-devtools Major
@tanstack/svelte-query-persist-client Major

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

@github-actions github-actions bot added documentation Improvements or additions to documentation package: svelte-query labels Feb 23, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0cf934c and 5048011.

📒 Files selected for processing (2)
  • packages/svelte-query/tests/mutationOptions/BaseExample.svelte
  • packages/svelte-query/tests/mutationOptions/mutationOptions.svelte.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/svelte-query/tests/mutationOptions/BaseExample.svelte

📝 Walkthrough

Walkthrough

Adds a new exported function mutationOptions to packages/svelte-query, with type overloads, documentation, changeset entry, and comprehensive runtime + type tests and a Svelte example demonstrating its usage.

Changes

Cohort / File(s) Summary
Changeset & Changelog
\.changeset/smart-spiders-sing.md
Adds a changeset recording a minor version bump and feature note for mutationOptions.
Docs Config
docs/config.json
Registers a new API reference entry for Svelte: Functions / mutationOptions.
Documentation Page
docs/framework/svelte/reference/functions/mutationOptions.md
Adds a documentation page describing mutationOptions including overloads, signatures, type parameters, and source reference.
Public API Export
packages/svelte-query/src/index.ts
Exports the new mutationOptions function from the package entry.
Implementation
packages/svelte-query/src/mutationOptions.ts
Introduces mutationOptions with multiple TypeScript overloads (required and optional mutationKey) and an implementation that returns the provided options.
Runtime Example & Tests
packages/svelte-query/tests/mutationOptions/BaseExample.svelte, packages/svelte-query/tests/mutationOptions/mutationOptions.svelte.test.ts
Adds a Svelte example and integration tests validating mutation counting, isMutating/clientIsMutating behavior, and UI-emitted state under various configs and timings.
Type Tests
packages/svelte-query/tests/mutationOptions/mutationOptions.test-d.ts
Adds extensive d.ts tests asserting type inference, callback typings, excess property errors, and interactions with createMutation/useMutationState/isMutating APIs.

Sequence Diagram(s)

sequenceDiagram
    participant Component
    participant MutationOptions as mutationOptions
    participant CreateMutation as createMutation
    participant QueryClient
    participant IsMutating as isMutating

    Component->>MutationOptions: provide CreateMutationOptions
    Note over MutationOptions: Enforce/reflect types (with/without mutationKey)
    MutationOptions-->>Component: return typed options

    Component->>CreateMutation: create mutation using options
    CreateMutation->>QueryClient: register mutation (cache)
    Component->>QueryClient: call mutate()
    QueryClient->>QueryClient: track active mutation(s)

    Component->>IsMutating: request count/state (optional filter)
    IsMutating-->>Component: return count/state
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hopped through types and tests today,
Wrapped options neatly so keys can play,
Docs and examples all in tune,
Mutations counted by noon. 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(svelte-query): add mutationOptions' accurately describes the main change: introducing a new mutationOptions function to svelte-query.
Description check ✅ Passed The PR description follows the template structure with all required sections completed: detailed changes, completed checklist items, and release impact documentation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@nx-cloud
Copy link

nx-cloud bot commented Feb 23, 2026

View your CI Pipeline Execution ↗ for commit 5048011

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

☁️ Nx Cloud last updated this comment at 2026-02-23 18:07:50 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 23, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 5048011

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/framework/svelte/reference/functions/mutationOptions.md`:
- Around line 8-48: The doc has duplicated "Call Signature" headings for the
overloads of the mutationOptions function causing MD024; update the two headings
so they are distinct (e.g., "Call Signature — Required mutationKey overload" and
"Call Signature — Omitted mutationKey overload" or similar) to describe each
overload clearly; locate the two headings around the mutationOptions function
declaration and CreateMutationOptions/mutationKey references and rename them to
avoid duplicate top-level headings while keeping the linked type references
intact.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb7dca5 and 0cf934c.

📒 Files selected for processing (8)
  • .changeset/smart-spiders-sing.md
  • docs/config.json
  • docs/framework/svelte/reference/functions/mutationOptions.md
  • packages/svelte-query/src/index.ts
  • packages/svelte-query/src/mutationOptions.ts
  • packages/svelte-query/tests/mutationOptions/BaseExample.svelte
  • packages/svelte-query/tests/mutationOptions/mutationOptions.svelte.test.ts
  • packages/svelte-query/tests/mutationOptions/mutationOptions.test-d.ts

Comment on lines +8 to +48
## Call Signature

```ts
function mutationOptions<TData, TError, TVariables, TOnMutateResult>(options): WithRequired<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, 'mutationKey'>
```

Defined in: [packages/svelte-query/src/mutationOptions.ts](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/mutationOptions.ts)

### Type Parameters

#### TData

`TData` = `unknown`

#### TError

`TError` = `Error`

#### TVariables

`TVariables` = `void`

#### TOnMutateResult

`TOnMutateResult` = `unknown`

### Parameters

#### options

`WithRequired`\<[`CreateMutationOptions`](../type-aliases/CreateMutationOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>, `'mutationKey'`\>

### Returns

`WithRequired`\<[`CreateMutationOptions`](../type-aliases/CreateMutationOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>, `'mutationKey'`\>

## Call Signature

```ts
function mutationOptions<TData, TError, TVariables, TOnMutateResult>(options): Omit<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, 'mutationKey'>
```
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Resolve duplicate "Call Signature" headings (MD024 warning).

Rename the headings to distinguish the overloads and avoid markdownlint warnings.

📝 Suggested heading tweak
-## Call Signature
+## Call Signature (with mutationKey)
@@
-## Call Signature
+## Call Signature (without mutationKey)
🧰 Tools
🪛 LanguageTool

[grammar] ~18-~18: Ensure spelling is correct
Context: ...nOptions.ts) ### Type Parameters #### TData TData = unknown #### TError TError = `E...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~26-~26: Ensure spelling is correct
Context: ... #### TError TError = Error #### TVariables TVariables = void #### TOnMutateResult `TOnMut...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~30-~30: Ensure spelling is correct
Context: ...TVariables TVariables = void #### TOnMutateResult TOnMutateResult = unknown ### Parameters #### optio...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🪛 markdownlint-cli2 (0.21.0)

[warning] 44-44: Multiple headings with the same content

(MD024, no-duplicate-heading)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/framework/svelte/reference/functions/mutationOptions.md` around lines 8
- 48, The doc has duplicated "Call Signature" headings for the overloads of the
mutationOptions function causing MD024; update the two headings so they are
distinct (e.g., "Call Signature — Required mutationKey overload" and "Call
Signature — Omitted mutationKey overload" or similar) to describe each overload
clearly; locate the two headings around the mutationOptions function declaration
and CreateMutationOptions/mutationKey references and rename them to avoid
duplicate top-level headings while keeping the linked type references intact.

…BaseExample and wrap test values with arrow functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation package: svelte-query

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant