Skip to content

Commit

Permalink
Merge pull request #2104 from reduxjs/feature/9.0-remove-batching
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Dec 10, 2023
2 parents dbdac99 + 6302797 commit 5bb3c4f
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 109 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
"bugs": "https://github.com/reduxjs/react-redux/issues",
"module": "dist/react-redux.legacy-esm.js",
"main": "dist/cjs/index.js",
"react-native": "./dist/react-redux.react-native.js",
"react-native": "./dist/react-redux.legacy-esm.js",
"types": "dist/react-redux.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/react-redux.d.ts",
"react-server": "./dist/rsc.mjs",
"react-native": "./dist/react-redux.react-native.js",
"react-native": "./dist/react-redux.legacy-esm.js",
"import": "./dist/react-redux.mjs",
"default": "./dist/cjs/index.js"
},
"./alternate-renderers": {
"types": "./dist/react-redux.d.ts",
"import": "./dist/react-redux.alternate-renderers.mjs"
"import": "./dist/react-redux.mjs",
"default": "./dist/cjs/index.js"
}
},
"sideEffects": false,
Expand Down
23 changes: 0 additions & 23 deletions src/alternate-renderers.ts

This file was deleted.

9 changes: 9 additions & 0 deletions src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { useStore, createStoreHook } from './hooks/useStore'

import shallowEqual from './utils/shallowEqual'
import type { Subscription } from './utils/Subscription'
import { defaultNoopBatch } from './utils/batch'

export * from './types'
export type {
Expand All @@ -49,6 +50,13 @@ export type {
ReactReduxContextValue,
Subscription,
}

/**
* @deprecated As of React 18, batching is enabled by default for ReactDOM and React Native.
* This is now a no-op that immediately runs the callback.
*/
const batch = defaultNoopBatch

export {
Provider,
ReactReduxContext,
Expand All @@ -60,4 +68,5 @@ export {
useStore,
createStoreHook,
shallowEqual,
batch,
}
13 changes: 0 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,10 @@
import * as React from 'react'
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector.js'

import { unstable_batchedUpdates as batchInternal } from './utils/reactBatchedUpdates'
import { setBatch } from './utils/batch'

import { initializeUseSelector } from './hooks/useSelector'
import { initializeConnect } from './components/connect'

initializeUseSelector(useSyncExternalStoreWithSelector)
initializeConnect(React.useSyncExternalStore)

// Enable batched updates in our subscriptions for use
// with standard React renderers (ReactDOM, React Native)
setBatch(batchInternal)

// Avoid needing `react-dom` in the final TS types
// by providing a simpler type for `batch`
const batch: (cb: () => void) => void = batchInternal

export { batch }

export * from './exports'
28 changes: 0 additions & 28 deletions src/react-native.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/utils/Subscription.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getBatch } from './batch'
import { defaultNoopBatch as batch } from './batch'

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

function createListenerCollection() {
const batch = getBatch()
let first: Listener | null = null
let last: Listener | null = null

Expand Down
11 changes: 1 addition & 10 deletions src/utils/batch.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
// Default to a dummy "batch" implementation that just runs the callback
function defaultNoopBatch(callback: () => void) {
export function defaultNoopBatch(callback: () => void) {
callback()
}

let batch = defaultNoopBatch

// Allow injecting another batching function later
export const setBatch = (newBatch: typeof defaultNoopBatch) =>
(batch = newBatch)

// Supply a getter just to skip dealing with ESM bindings
export const getBatch = () => batch
5 changes: 0 additions & 5 deletions src/utils/reactBatchedUpdates.native.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/reactBatchedUpdates.ts

This file was deleted.

6 changes: 0 additions & 6 deletions test/react-native/batch-integration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ describe('React Native', () => {

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

describe('batch', () => {
it('batch should be RN unstable_batchedUpdates', () => {
expect(batch).toBe(unstable_batchedUpdates)
})
})

describe('useIsomorphicLayoutEffect', () => {
it('useIsomorphicLayoutEffect should be useLayoutEffect', () => {
expect(useIsomorphicLayoutEffect).toBe(useLayoutEffect)
Expand Down
18 changes: 0 additions & 18 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,6 @@ export default defineConfig((options) => {
outExtension: () => ({ js: '.mjs' }),
minify: true,
},
// "Alternate renderers" entry point with a no-op batch
{
...commonOptions,
entry: {
'react-redux.alternate-renderers': 'src/alternate-renderers.ts',
},
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
},
// React Native requires a separate entry point for `"react-native"` batch dep
{
...commonOptions,
entry: {
'react-redux.react-native': 'src/react-native.ts',
},
format: ['esm'],
outExtension: () => ({ js: '.js' }),
},
// CJS development
{
...commonOptions,
Expand Down

0 comments on commit 5bb3c4f

Please sign in to comment.