@tanstack/react-query 5.8.7 → 5.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,6 +70,26 @@ const transformFilterAwareUsages = ({
70
70
  const replacer = (path) => {
71
71
  const node = path.node
72
72
 
73
+ const isFunctionDefinition = (functionArgument) => {
74
+ if (utils.isFunctionDefinition(functionArgument)) {
75
+ return true
76
+ }
77
+
78
+ if (utils.isIdentifier(functionArgument)) {
79
+ const binding = v5Utils.getBindingFromScope(
80
+ path,
81
+ functionArgument.name,
82
+ filePath,
83
+ )
84
+
85
+ const isVariableDeclarator = jscodeshift.match(binding, {
86
+ type: jscodeshift.VariableDeclarator.name,
87
+ })
88
+
89
+ return isVariableDeclarator && utils.isFunctionDefinition(binding.init)
90
+ }
91
+ }
92
+
73
93
  try {
74
94
  // If the given method/function call matches certain criteria, the node doesn't need to be replaced, this step can be skipped.
75
95
  if (canSkipReplacement(node, config.keyName)) {
@@ -129,6 +149,43 @@ const transformFilterAwareUsages = ({
129
149
  if (secondParameter) {
130
150
  const createdObjectExpression = functionArguments[0]
131
151
 
152
+ if (isFunctionDefinition(secondParameter)) {
153
+ const objectExpression = jscodeshift.objectExpression([
154
+ jscodeshift.property(
155
+ 'init',
156
+ jscodeshift.identifier('queryKey'),
157
+ node.arguments[0],
158
+ ),
159
+ jscodeshift.property(
160
+ 'init',
161
+ jscodeshift.identifier('queryFn'),
162
+ secondParameter,
163
+ ),
164
+ ])
165
+
166
+ const thirdArgument = node.arguments[2]
167
+
168
+ if (thirdArgument) {
169
+ // If it's an object expression, we can copy the properties from it to the newly created object expression.
170
+ if (utils.isObjectExpression(thirdArgument)) {
171
+ v5Utils.copyPropertiesFromSource(
172
+ thirdArgument,
173
+ objectExpression,
174
+ predicate,
175
+ )
176
+ } else {
177
+ // Otherwise, we simply spread the third argument in the newly created object expression.
178
+ objectExpression.properties.push(
179
+ jscodeshift.spreadElement(thirdArgument),
180
+ )
181
+ }
182
+ }
183
+
184
+ return jscodeshift.callExpression(node.original.callee, [
185
+ objectExpression,
186
+ ])
187
+ }
188
+
132
189
  /**
133
190
  * If it has a second argument, and it's an object expression, then we get the properties from it
134
191
  * (except the "queryKey" or "mutationKey" properties), because these arguments will also be moved to the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query",
3
- "version": "5.8.7",
3
+ "version": "5.8.9",
4
4
  "description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -1077,15 +1077,11 @@ describe('useQueries', () => {
1077
1077
  rendered.getByText('data: true first result 1,second result 1'),
1078
1078
  )
1079
1079
 
1080
- expect(results.length).toBe(5)
1080
+ const length = results.length
1081
1081
 
1082
- expect(results[3]).toStrictEqual({
1083
- combined: true,
1084
- refetch: expect.any(Function),
1085
- res: 'first result 1,second result 0',
1086
- })
1082
+ expect([4, 5]).toContain(results.length)
1087
1083
 
1088
- expect(results[4]).toStrictEqual({
1084
+ expect(results[results.length - 1]).toStrictEqual({
1089
1085
  combined: true,
1090
1086
  refetch: expect.any(Function),
1091
1087
  res: 'first result 1,second result 1',
@@ -1095,6 +1091,6 @@ describe('useQueries', () => {
1095
1091
 
1096
1092
  await sleep(100)
1097
1093
  // no further re-render because data didn't change
1098
- expect(results.length).toBe(5)
1094
+ expect(results.length).toBe(length)
1099
1095
  })
1100
1096
  })