Skip to content

Commit f7db4ca

Browse files
authoredMay 14, 2024
fix: unstable reference (Issue 1359) (#1374)
* Issue 1359 * added import for useCallback * revert lock file changes * chore: fix formatting
1 parent a61d26a commit f7db4ca

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed
 

‎packages/query/src/index.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ import {
4545
vueUnRefParams,
4646
} from './utils';
4747

48+
const REACT_DEPENDENCIES: GeneratorDependency[] = [
49+
{
50+
exports: [
51+
{
52+
name: 'useCallback',
53+
values: true,
54+
},
55+
],
56+
dependency: 'react',
57+
},
58+
];
59+
4860
const AXIOS_DEPENDENCIES: GeneratorDependency[] = [
4961
{
5062
exports: [
@@ -208,6 +220,7 @@ export const getReactQueryDependencies: ClientDependenciesBuilder = (
208220
packageJson?.devDependencies?.['@tanstack/react-query'];
209221

210222
return [
223+
...(hasGlobalMutator ? REACT_DEPENDENCIES : []),
211224
...(!hasGlobalMutator ? AXIOS_DEPENDENCIES : []),
212225
...(hasParamsSerializerOptions ? PARAMS_SERIALIZER_DEPENDENCIES : []),
213226
...(hasReactQuery && !hasReactQueryV4
@@ -451,7 +464,7 @@ const generateQueryRequestFunction = (
451464
response.definition.success || 'unknown'
452465
}>();
453466
454-
return (\n ${propsImplementation}\n ${
467+
return useCallback((\n ${propsImplementation}\n ${
455468
isRequestOptions && mutator.hasSecondArg
456469
? `options${context.output.optionsParamRequired ? '' : '?'}: SecondParameter<ReturnType<typeof ${mutator.name}>>,`
457470
: ''
@@ -461,7 +474,7 @@ const generateQueryRequestFunction = (
461474
return ${operationName}(
462475
${mutatorConfig},
463476
${requestOptions});
464-
}
477+
}, [${operationName}])
465478
}
466479
`;
467480
}

‎tests/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@tanstack/react-query": "^4.22.0",
3434
"@tanstack/svelte-query": "^4.24.9",
3535
"@tanstack/vue-query": "^4.22.0",
36+
"@types/react": "18.3.2",
3637
"axios": "^0.26.1",
3738
"msw": "^2.0.2",
3839
"swr": "^2.2.4",

‎tests/yarn.lock

+18
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@
139139
resolved "https://registry.yarnpkg.com/@types/js-levenshtein/-/js-levenshtein-1.1.2.tgz#e88f365d6a34beeaff9654706b99a790b5a5aabd"
140140
integrity sha512-/NCbMABw2uacuyE16Iwka1EzREDD50/W2ggRBad0y1WHBvAkvR9OEINxModVY7D428gXBe0igeVX7bUc9GaslQ==
141141

142+
"@types/prop-types@*":
143+
version "15.7.12"
144+
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.12.tgz#12bb1e2be27293c1406acb6af1c3f3a1481d98c6"
145+
integrity sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==
146+
147+
"@types/react@18.3.2":
148+
version "18.3.2"
149+
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.3.2.tgz#462ae4904973bc212fa910424d901e3d137dbfcd"
150+
integrity sha512-Btgg89dAnqD4vV7R3hlwOxgqobUQKgx3MmrQRi0yYbs/P0ym8XozIAlkqVilPqHQwXs4e9Tf63rrCgl58BcO4w==
151+
dependencies:
152+
"@types/prop-types" "*"
153+
csstype "^3.0.2"
154+
142155
"@types/statuses@^2.0.1":
143156
version "2.0.3"
144157
resolved "https://registry.yarnpkg.com/@types/statuses/-/statuses-2.0.3.tgz#9286ef63c99ed9fd739db7f7db5ab9bd6160ab33"
@@ -445,6 +458,11 @@ cross-spawn@^6.0.5:
445458
shebang-command "^1.2.0"
446459
which "^1.2.9"
447460

461+
csstype@^3.0.2:
462+
version "3.1.3"
463+
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.3.tgz#d80ff294d114fb0e6ac500fbf85b60137d7eff81"
464+
integrity sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==
465+
448466
csstype@^3.1.1:
449467
version "3.1.2"
450468
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b"

0 commit comments

Comments
 (0)
Please sign in to comment.