Skip to content

Commit cd6b1b7

Browse files
authored
fix(query): pass enabled option into queryOptions mutator (#3389)
* fix(query): pass enabled option into queryOptions mutator When `allParamsOptional` is combined with a custom `queryOptions` mutator, the generated query options helper passed `{ ...queryOptions, queryKey, queryFn }` to the mutator, dropping the `enabled` guard (and any override options) that the non-mutator branch emits via `queryOptionsImp`. The query then ran even while a required path param was nullish, hitting a broken URL. Pass the same object shape the non-mutator branch returns so the `enabled` guard reaches the mutator, and so `...queryOptions` stays last and remains overridable. Closes #1522 * test(query): match issue-1522 mutator call verbatim The issue-1522 regression test sliced the generated `customQueryOptions(...)` call by searching for the first `});`, which a nested call site in the argument could truncate. Match the whole call verbatim instead — generation is deterministic — and assert it appears once per query helper.
1 parent c2959b3 commit cd6b1b7

9 files changed

Lines changed: 585 additions & 6 deletions

File tree

packages/query/src/query-generator.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,12 @@ ${hookOptions}
649649
650650
${
651651
queryOptionsMutator
652-
? `const customOptions = ${
652+
? // Pass the same options object the non-mutator branch returns so
653+
// generated guards (e.g. the `enabled` clause for nullish path
654+
// params) reach the mutator instead of being dropped. See #1522.
655+
`const customOptions = ${
653656
queryOptionsMutator.name
654-
}({...queryOptions, queryKey, queryFn}${
657+
}({ queryKey, queryFn, ${queryOptionsImp}}${
655658
queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ''
656659
}${
657660
queryOptionsMutator.hasThirdArg ? `, { url: \`${route}\` }` : ''

0 commit comments

Comments
 (0)