feat(svelte-query): add 'mutationOptions'#10175
feat(svelte-query): add 'mutationOptions'#10175sukvvon wants to merge 9 commits intoTanStack:mainfrom
Conversation
…nction for type-safe mutation configuration
🦋 Changeset detectedLatest commit: 3383e4c The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new exported Svelte helper Changes
Sequence Diagram(s)sequenceDiagram
participant Component
participant MutationOptions as mutationOptions
participant CreateMutation as createMutation
participant QueryClient
participant IsMutating as useIsMutating
Component->>MutationOptions: provide CreateMutationOptions (with/without mutationKey)
Note over MutationOptions: type overload selection (require/omit mutationKey)
MutationOptions-->>Component: return typed options
Component->>CreateMutation: create mutation using returned options
CreateMutation->>QueryClient: register mutation in mutation cache
Component->>QueryClient: call mutate()
QueryClient->>QueryClient: track active mutation(s)
Component->>IsMutating: query counts/state (optional filter by mutationKey)
IsMutating-->>Component: return count/state
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
|
View your CI Pipeline Execution ↗ for commit 3383e4c
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
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
📒 Files selected for processing (8)
.changeset/smart-spiders-sing.mddocs/config.jsondocs/framework/svelte/reference/functions/mutationOptions.mdpackages/svelte-query/src/index.tspackages/svelte-query/src/mutationOptions.tspackages/svelte-query/tests/mutationOptions/BaseExample.sveltepackages/svelte-query/tests/mutationOptions/mutationOptions.svelte.test.tspackages/svelte-query/tests/mutationOptions/mutationOptions.test-d.ts
| ## 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'> | ||
| ``` |
There was a problem hiding this comment.
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
…Event' and assertion blocks
…ample and MultiExample for single and multi mutation tests
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/svelte-query/tests/mutationOptions/mutationOptions.svelte.test.ts (1)
262-289: Order-dependent assertion — consider usingarrayContainingfor resilience.The expected value
["data1","data2"]relies on the mutation cache preserving insertion order when both mutations complete simultaneously. This is currently deterministic, but if cache ordering semantics ever change the test will silently produce a different order and fail.♻️ Optional: order-agnostic assertion
- expect( - rendered.getByText('mutationState: ["data1","data2"]'), - ).toBeInTheDocument() + const text = rendered.getByRole('status', { name: /mutationState/i })?.textContent + ?? rendered.container.textContent ?? '' + const parsed = JSON.parse(text.replace('mutationState: ', '')) + expect(parsed).toEqual(expect.arrayContaining(['data1', 'data2'])) + expect(parsed).toHaveLength(2)Alternatively, if the text format is rendered as a single DOM node, the existing assertion is fine to keep as-is given the guaranteed insertion order.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/svelte-query/tests/mutationOptions/mutationOptions.svelte.test.ts` around lines 262 - 289, The assertion is order-dependent and may fail if cache ordering changes; update the test inside the "should return mutation states when used with useMutationState" case to make the final expectation order-agnostic by matching the rendered mutationState contents with an order-insensitive check (e.g., use an arrayContaining-style assertion or verify both "data1" and "data2" exist regardless of order) when inspecting the BaseExample render output for mutationState after calling mutationOpts1/mutationOpts2 and advancing timers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/svelte-query/tests/mutationOptions/mutationOptions.svelte.test.ts`:
- Around line 262-289: The assertion is order-dependent and may fail if cache
ordering changes; update the test inside the "should return mutation states when
used with useMutationState" case to make the final expectation order-agnostic by
matching the rendered mutationState contents with an order-insensitive check
(e.g., use an arrayContaining-style assertion or verify both "data1" and "data2"
exist regardless of order) when inspecting the BaseExample render output for
mutationState after calling mutationOpts1/mutationOpts2 and advancing timers.
🎯 Changes
Add
mutationOptionsidentity function to@tanstack/svelte-queryfor type-safe mutation configuration, matching the existing implementation inreact-queryandpreact-query.mutationOptionswith two overloads (with/withoutmutationKey)✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
New Features
Documentation
Tests
Chores