Skip to content

Commit 5bb3c4f

Browse files
authored
Merge pull request #2104 from reduxjs/feature/9.0-remove-batching
2 parents dbdac99 + 6302797 commit 5bb3c4f

11 files changed

+15
-109
lines changed

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@
1414
"bugs": "https://github.com/reduxjs/react-redux/issues",
1515
"module": "dist/react-redux.legacy-esm.js",
1616
"main": "dist/cjs/index.js",
17-
"react-native": "./dist/react-redux.react-native.js",
17+
"react-native": "./dist/react-redux.legacy-esm.js",
1818
"types": "dist/react-redux.d.ts",
1919
"exports": {
2020
"./package.json": "./package.json",
2121
".": {
2222
"types": "./dist/react-redux.d.ts",
2323
"react-server": "./dist/rsc.mjs",
24-
"react-native": "./dist/react-redux.react-native.js",
24+
"react-native": "./dist/react-redux.legacy-esm.js",
2525
"import": "./dist/react-redux.mjs",
2626
"default": "./dist/cjs/index.js"
2727
},
2828
"./alternate-renderers": {
2929
"types": "./dist/react-redux.d.ts",
30-
"import": "./dist/react-redux.alternate-renderers.mjs"
30+
"import": "./dist/react-redux.mjs",
31+
"default": "./dist/cjs/index.js"
3132
}
3233
},
3334
"sideEffects": false,

src/alternate-renderers.ts

-23
This file was deleted.

src/exports.ts

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { useStore, createStoreHook } from './hooks/useStore'
2828

2929
import shallowEqual from './utils/shallowEqual'
3030
import type { Subscription } from './utils/Subscription'
31+
import { defaultNoopBatch } from './utils/batch'
3132

3233
export * from './types'
3334
export type {
@@ -49,6 +50,13 @@ export type {
4950
ReactReduxContextValue,
5051
Subscription,
5152
}
53+
54+
/**
55+
* @deprecated As of React 18, batching is enabled by default for ReactDOM and React Native.
56+
* This is now a no-op that immediately runs the callback.
57+
*/
58+
const batch = defaultNoopBatch
59+
5260
export {
5361
Provider,
5462
ReactReduxContext,
@@ -60,4 +68,5 @@ export {
6068
useStore,
6169
createStoreHook,
6270
shallowEqual,
71+
batch,
6372
}

src/index.ts

-13
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,10 @@
66
import * as React from 'react'
77
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector.js'
88

9-
import { unstable_batchedUpdates as batchInternal } from './utils/reactBatchedUpdates'
10-
import { setBatch } from './utils/batch'
11-
129
import { initializeUseSelector } from './hooks/useSelector'
1310
import { initializeConnect } from './components/connect'
1411

1512
initializeUseSelector(useSyncExternalStoreWithSelector)
1613
initializeConnect(React.useSyncExternalStore)
1714

18-
// Enable batched updates in our subscriptions for use
19-
// with standard React renderers (ReactDOM, React Native)
20-
setBatch(batchInternal)
21-
22-
// Avoid needing `react-dom` in the final TS types
23-
// by providing a simpler type for `batch`
24-
const batch: (cb: () => void) => void = batchInternal
25-
26-
export { batch }
27-
2815
export * from './exports'

src/react-native.ts

-28
This file was deleted.

src/utils/Subscription.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getBatch } from './batch'
1+
import { defaultNoopBatch as batch } from './batch'
22

33
// encapsulates the subscription logic for connecting a component to the redux store, as
44
// well as nesting subscriptions of descendant components, so that we can ensure the
@@ -13,7 +13,6 @@ type Listener = {
1313
}
1414

1515
function createListenerCollection() {
16-
const batch = getBatch()
1716
let first: Listener | null = null
1817
let last: Listener | null = null
1918

src/utils/batch.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
// Default to a dummy "batch" implementation that just runs the callback
2-
function defaultNoopBatch(callback: () => void) {
2+
export function defaultNoopBatch(callback: () => void) {
33
callback()
44
}
5-
6-
let batch = defaultNoopBatch
7-
8-
// Allow injecting another batching function later
9-
export const setBatch = (newBatch: typeof defaultNoopBatch) =>
10-
(batch = newBatch)
11-
12-
// Supply a getter just to skip dealing with ESM bindings
13-
export const getBatch = () => batch

src/utils/reactBatchedUpdates.native.ts

-5
This file was deleted.

src/utils/reactBatchedUpdates.ts

-1
This file was deleted.

test/react-native/batch-integration.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ describe('React Native', () => {
5353

5454
afterEach(() => rtl.cleanup())
5555

56-
describe('batch', () => {
57-
it('batch should be RN unstable_batchedUpdates', () => {
58-
expect(batch).toBe(unstable_batchedUpdates)
59-
})
60-
})
61-
6256
describe('useIsomorphicLayoutEffect', () => {
6357
it('useIsomorphicLayoutEffect should be useLayoutEffect', () => {
6458
expect(useIsomorphicLayoutEffect).toBe(useLayoutEffect)

tsup.config.ts

-18
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,6 @@ export default defineConfig((options) => {
6767
outExtension: () => ({ js: '.mjs' }),
6868
minify: true,
6969
},
70-
// "Alternate renderers" entry point with a no-op batch
71-
{
72-
...commonOptions,
73-
entry: {
74-
'react-redux.alternate-renderers': 'src/alternate-renderers.ts',
75-
},
76-
format: ['esm'],
77-
outExtension: () => ({ js: '.mjs' }),
78-
},
79-
// React Native requires a separate entry point for `"react-native"` batch dep
80-
{
81-
...commonOptions,
82-
entry: {
83-
'react-redux.react-native': 'src/react-native.ts',
84-
},
85-
format: ['esm'],
86-
outExtension: () => ({ js: '.js' }),
87-
},
8870
// CJS development
8971
{
9072
...commonOptions,

0 commit comments

Comments
 (0)