Skip to content

Commit 24b0ddd

Browse files
RodSarhanTkDodo
andauthored
refactor(reactBatchedUpdates): remove the side effect that sets batchNotifyFn in react (#4699)
* refactor(reactBatchedUpdates): remove the side effect that sets unstable_batchedUpdates as batchNotifyFn in react and react-native * docs(v5 migration guide): explain unstable_batchedUpdates removal Co-authored-by: Dominik Dorfmeister <[email protected]>
1 parent fabc5d7 commit 24b0ddd

File tree

7 files changed

+16
-19
lines changed

7 files changed

+16
-19
lines changed

docs/react/guides/migrating-to-react-query-5.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,18 @@ useQuery<number, string>({
161161
### eslint `prefer-query-object-syntax` rule is removed
162162

163163
Since the only supported syntax now is the object syntax, this rule is no longer needed
164+
165+
### No longer using `unstable_batchedUpdates` as the batching function in React and React Native
166+
167+
Since the function `unstable_batchedUpdates` is noop in React 18, it will no longer be automatically set as the batching function in `react-query`.
168+
169+
If your framework supports a custom batching function, you can let TanStack Query know about it by calling `notifyManager.setBatchNotifyFunction`.
170+
171+
For example, this is how the batch function is set in `solid-query`:
172+
173+
```ts
174+
import { notifyManager } from '@tanstack/query-core'
175+
import { batch } from 'solid-js'
176+
177+
notifyManager.setBatchNotifyFunction(batch)
178+
```

packages/react-query/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
},
2222
"./package.json": "./package.json"
2323
},
24-
"sideEffects": [
25-
"./src/setBatchUpdatesFn.ts"
26-
],
24+
"sideEffects": false,
2725
"scripts": {
2826
"clean": "rm -rf ./build",
2927
"test:codemods": "../../node_modules/.bin/jest --config codemods/jest.config.js",

packages/react-query/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/* istanbul ignore file */
22

3-
// Side effects
4-
import './setBatchUpdatesFn'
5-
63
// Re-export core
74
export * from '@tanstack/query-core'
85

packages/react-query/src/reactBatchedUpdates.native.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/react-query/src/reactBatchedUpdates.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/react-query/src/setBatchUpdatesFn.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

rollup.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export default function rollup(options: RollupOptions): RollupOptions[] {
9191
outputFile: 'index',
9292
entryFile: [
9393
'src/index.ts',
94-
'src/reactBatchedUpdates.native.ts',
9594
],
9695
globals: {
9796
react: 'React',
@@ -360,8 +359,6 @@ function cjs({
360359
replace({
361360
// TODO: figure out a better way to produce extensionless cjs imports
362361
"require('./logger.js')": "require('./logger')",
363-
"require('./reactBatchedUpdates.js')":
364-
"require('./reactBatchedUpdates')",
365362
preventAssignment: true,
366363
delimiters: ['', ''],
367364
}),

0 commit comments

Comments
 (0)