Skip to content

Commit 4eee88b

Browse files
authored
Merge pull request #2095 from reduxjs/v9.0-integration
2 parents 18c2b89 + 152b472 commit 4eee88b

40 files changed

+3686
-2788
lines changed

.github/workflows/test.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
matrix:
5353
node: ['16.x']
5454
ts: ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2']
55+
5556
steps:
5657
- name: Checkout repo
5758
uses: actions/checkout@v3
@@ -120,6 +121,10 @@ jobs:
120121
- name: Clone RTK repo
121122
run: git clone https://github.com/reduxjs/redux-toolkit.git ./redux-toolkit
122123

124+
- name: Check out v2.0-integration
125+
working-directory: ./redux-toolkit
126+
run: git checkout v2.0-integration
127+
123128
- name: Check folder contents
124129
run: ls -l .
125130

@@ -135,7 +140,7 @@ jobs:
135140

136141
- name: Install deps
137142
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
138-
run: rm yarn.lock && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn add msw@latest
143+
run: rm yarn.lock && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install
139144

140145
- name: Install Playwright browser if necessary
141146
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
build*/

.babelrc.js babel.config.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
},
1717
],
1818
'@babel/preset-typescript',
19+
'module:metro-react-native-babel-preset',
1920
],
2021
plugins: [
2122
['@babel/proposal-decorators', { legacy: true }],
@@ -24,15 +25,6 @@ module.exports = {
2425
['@babel/plugin-proposal-private-methods', { loose: true }],
2526
['@babel/plugin-proposal-private-property-in-object', { loose: true }],
2627
cjs && ['@babel/transform-modules-commonjs'],
27-
[
28-
'@babel/transform-runtime',
29-
{
30-
useESModules: !cjs,
31-
version: require('./package.json').dependencies[
32-
'@babel/runtime'
33-
].replace(/^[^0-9]*/, ''),
34-
},
35-
],
3628
].filter(Boolean),
3729
assumptions: {
3830
enumerableModuleMeta: true,

docs/api/Provider.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ interface ProviderProps<A extends Action = AnyAction, S = any> {
3939
* to create a context to be used.
4040
* If this is used, you'll need to customize `connect` by supplying the same
4141
* context provided to the Provider.
42-
* Initial value doesn't matter, as it is overwritten with the internal state of Provider.
42+
* Set the initial value to null, and the hooks will error
43+
* if this is not overwritten by Provider.
4344
*/
44-
context?: Context<ReactReduxContextValue<S, A>>
45+
context?: Context<ReactReduxContextValue<S, A> | null>
4546

4647
/** Global configuration for the `useSelector` stability check */
4748
stabilityCheck?: StabilityCheck

docs/api/hooks.md

+25-9
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ From there, you may import any of the listed React Redux hooks APIs and use them
4848
type RootState = ReturnType<typeof store.getState>
4949
type SelectorFn = <Selected>(state: RootState) => Selected
5050
type EqualityFn = (a: any, b: any) => boolean
51-
export type CheckFrequency = 'never' | 'once' | 'always'
51+
export type DevModeCheckFrequency = 'never' | 'once' | 'always'
5252

5353
interface UseSelectorOptions {
5454
equalityFn?: EqualityFn
55-
stabilityCheck?: CheckFrequency
56-
noopCheck?: CheckFrequency
55+
devModeChecks?: {
56+
stabilityCheck?: DevModeCheckFrequency
57+
identityFunctionCheck?: DevModeCheckFrequency
58+
}
5759
}
5860

5961
const result: Selected = useSelector(
@@ -296,14 +298,24 @@ By default, this will only happen when the selector is first called. You can con
296298

297299
```tsx title="Individual hook setting"
298300
function Component() {
299-
const count = useSelector(selectCount, { stabilityCheck: 'never' })
301+
const count = useSelector(selectCount, {
302+
devModeChecks: { stabilityCheck: 'never' },
303+
})
300304
// run once (default)
301-
const user = useSelector(selectUser, { stabilityCheck: 'once' })
305+
const user = useSelector(selectUser, {
306+
devModeChecks: { stabilityCheck: 'once' },
307+
})
302308
// ...
303309
}
304310
```
305311

306-
#### No-op selector check
312+
#### Identity Function (`state => state`) Check
313+
314+
:::danger Breaking Change!
315+
316+
This was previously referred to as `noopCheck`.
317+
318+
:::
307319

308320
In development, a check is conducted on the result returned by the selector. It warns in the console if the result is the same as the parameter passed in, i.e. the root state.
309321

@@ -321,16 +333,20 @@ const user = useSelector((state) => state.auth.currentUser)
321333
By default, this will only happen when the selector is first called. You can configure the check in the Provider or at each `useSelector` call.
322334

323335
```tsx title="Global setting via context"
324-
<Provider store={store} noopCheck="always">
336+
<Provider store={store} identityFunctionCheck="always">
325337
{children}
326338
</Provider>
327339
```
328340

329341
```tsx title="Individual hook setting"
330342
function Component() {
331-
const count = useSelector(selectCount, { noopCheck: 'never' })
343+
const count = useSelector(selectCount, {
344+
devModeChecks: { identityFunctionCheck: 'never' },
345+
})
332346
// run once (default)
333-
const user = useSelector(selectUser, { noopCheck: 'once' })
347+
const user = useSelector(selectUser, {
348+
devModeChecks: { identityFunctionCheck: 'once' },
349+
})
334350
// ...
335351
}
336352
```

docs/using-react-redux/accessing-store.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Redux store accessible to deeply nested connected components. As of React Redux
2727
by a single default context object instance generated by `React.createContext()`, called `ReactReduxContext`.
2828

2929
React Redux's `<Provider>` component uses `<ReactReduxContext.Provider>` to put the Redux store and the current store
30-
state into context, and `connect` uses `<ReactReduxContext.Consumer>` to read those values and handle updates.
30+
state into context, and `connect` uses `useContext(ReactReduxContext)` to read those values and handle updates.
3131

3232
## Using the `useStore` Hook
3333

@@ -87,8 +87,8 @@ This also provides a natural isolation of the stores as they live in separate co
8787

8888
```js
8989
// a naive example
90-
const ContextA = React.createContext();
91-
const ContextB = React.createContext();
90+
const ContextA = React.createContext(null);
91+
const ContextB = React.createContext(null);
9292

9393
// assuming reducerA and reducerB are proper reducer functions
9494
const storeA = createStore(reducerA);

jest.config.js

+9-37
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,30 @@
1-
const { defaults: tsjPreset } = require('ts-jest/presets')
2-
3-
const defaults = {
4-
coverageDirectory: './coverage/',
5-
collectCoverage: true,
6-
testURL: 'http://localhost',
7-
}
1+
process.env.TS_JEST_DISABLE_VER_CHECKER = true
82

93
const NORMAL_TEST_FOLDERS = ['components', 'hooks', 'integration', 'utils']
104

115
const tsTestFolderPath = (folderName) =>
126
`<rootDir>/test/${folderName}/**/*.{ts,tsx}`
137

148
const tsStandardConfig = {
15-
...defaults,
16-
displayName: 'ReactDOM 18 (Shim)',
9+
displayName: 'ReactDOM 18',
1710
preset: 'ts-jest',
1811
testMatch: NORMAL_TEST_FOLDERS.map(tsTestFolderPath),
12+
testEnvironment: 'jsdom',
13+
setupFilesAfterEnv: ['<rootDir>/jest.setupAfter.js'],
1914
}
2015

2116
const rnConfig = {
22-
...defaults,
2317
displayName: 'React Native',
2418
testMatch: [tsTestFolderPath('react-native')],
2519
preset: 'react-native',
2620
transform: {
27-
'^.+\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
28-
...tsjPreset.transform,
29-
},
30-
}
31-
32-
const standardReact17Config = {
33-
...tsStandardConfig,
34-
displayName: 'ReactDOM 17',
35-
moduleNameMapper: {
36-
'^react$': 'react-17',
37-
'^react-dom$': 'react-dom-17',
38-
'^react-test-renderer$': 'react-test-renderer-17',
39-
'^@testing-library/react$': '@testing-library/react-12',
40-
},
41-
}
42-
43-
const nextEntryConfig = {
44-
...tsStandardConfig,
45-
displayName: 'ReactDOM 18 (Next)',
46-
moduleNameMapper: {
47-
'../../src/index': '<rootDir>/src/next',
21+
'^.+\\.(js|jsx|ts|tsx)$': [
22+
'babel-jest',
23+
{ configFile: './babel.config.js' }, // <- cannot use rootDir here
24+
],
4825
},
4926
}
5027

5128
module.exports = {
52-
projects: [
53-
tsStandardConfig,
54-
rnConfig,
55-
standardReact17Config,
56-
nextEntryConfig,
57-
],
29+
projects: [tsStandardConfig, rnConfig],
5830
}

jest.setupAfter.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { TextEncoder, TextDecoder } = require('util')
2+
global.TextEncoder = TextEncoder
3+
global.TextDecoder = TextDecoder

package.json

+41-47
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux",
3-
"version": "8.1.3",
3+
"version": "9.0.0-rc.0",
44
"description": "Official React bindings for Redux",
55
"keywords": [
66
"react",
@@ -12,23 +12,28 @@
1212
"homepage": "https://github.com/reduxjs/react-redux",
1313
"repository": "github:reduxjs/react-redux",
1414
"bugs": "https://github.com/reduxjs/react-redux/issues",
15-
"main": "./lib/index.js",
16-
"types": "./es/index.d.ts",
17-
"unpkg": "dist/react-redux.js",
18-
"module": "es/index.js",
15+
"module": "dist/react-redux.legacy-esm.js",
16+
"main": "dist/cjs/index.js",
17+
"types": "dist/react-redux.d.ts",
18+
"exports": {
19+
"./package.json": "./package.json",
20+
".": {
21+
"types": "./dist/react-redux.d.ts",
22+
"react-server": "./dist/rsc.mjs",
23+
"import": "./dist/react-redux.mjs",
24+
"default": "./dist/cjs/index.js"
25+
},
26+
"./alternate-renderers": {
27+
"types": "./dist/react-redux.d.ts",
28+
"import": "./dist/react-redux.alternate-renderers.mjs"
29+
}
30+
},
31+
"sideEffects": false,
1932
"files": [
20-
"dist",
21-
"lib",
22-
"src",
23-
"es"
33+
"dist"
2434
],
2535
"scripts": {
26-
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --extensions \".js,.ts,.tsx\" --out-dir lib",
27-
"build:es": "babel src --extensions \".js,.ts,.tsx\" --out-dir es",
28-
"build:umd": "cross-env NODE_ENV=development rollup -c -o dist/react-redux.js",
29-
"build:umd:min": "cross-env NODE_ENV=production rollup -c -o dist/react-redux.min.js",
30-
"build:types": "tsc",
31-
"build": "yarn build:types && yarn build:commonjs && yarn build:es && yarn build:umd && yarn build:umd:min",
36+
"build": "tsup",
3237
"clean": "rimraf lib dist es coverage",
3338
"api-types": "api-extractor run --local",
3439
"format": "prettier --write \"{src,test}/**/*.{js,ts,tsx}\" \"docs/**/*.md\"",
@@ -40,12 +45,12 @@
4045
"coverage": "codecov"
4146
},
4247
"peerDependencies": {
43-
"@types/react": "^16.8 || ^17.0 || ^18.0",
44-
"@types/react-dom": "^16.8 || ^17.0 || ^18.0",
45-
"react": "^16.8 || ^17.0 || ^18.0",
46-
"react-dom": "^16.8 || ^17.0 || ^18.0",
47-
"react-native": ">=0.59",
48-
"redux": "^4 || ^5.0.0-beta.0"
48+
"@types/react": "^18.2.41",
49+
"@types/react-dom": "^18.2.17",
50+
"react": "^18.0",
51+
"react-dom": "^18.0",
52+
"react-native": ">=0.71",
53+
"redux": "^5.0.0-rc.0"
4954
},
5055
"peerDependenciesMeta": {
5156
"@types/react": {
@@ -65,44 +70,35 @@
6570
}
6671
},
6772
"dependencies": {
68-
"@babel/runtime": "^7.12.1",
69-
"@types/hoist-non-react-statics": "^3.3.1",
7073
"@types/use-sync-external-store": "^0.0.3",
71-
"hoist-non-react-statics": "^3.3.2",
72-
"react-is": "^18.0.0",
7374
"use-sync-external-store": "^1.0.0"
7475
},
7576
"devDependencies": {
7677
"@babel/cli": "^7.12.1",
7778
"@babel/core": "^7.12.3",
7879
"@babel/plugin-proposal-decorators": "^7.12.1",
7980
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
81+
"@babel/plugin-transform-flow-strip-types": "^7.22.5",
8082
"@babel/plugin-transform-react-display-name": "^7.12.1",
8183
"@babel/plugin-transform-react-jsx": "^7.12.1",
8284
"@babel/plugin-transform-runtime": "^7.12.1",
8385
"@babel/preset-env": "^7.12.1",
8486
"@babel/preset-typescript": "^7.14.5",
8587
"@microsoft/api-extractor": "^7.18.1",
86-
"@reduxjs/toolkit": "^1.9.5",
87-
"@rollup/plugin-babel": "^5.2.1",
88-
"@rollup/plugin-commonjs": "^15.1.0",
89-
"@rollup/plugin-node-resolve": "^9.0.0",
90-
"@rollup/plugin-replace": "^2.3.3",
88+
"@reduxjs/toolkit": "^2.0.0-beta.4",
9189
"@testing-library/jest-dom": "^5.11.5",
9290
"@testing-library/jest-native": "^3.4.3",
9391
"@testing-library/react": "13.0.0",
9492
"@testing-library/react-12": "npm:@testing-library/react@^12",
9593
"@testing-library/react-hooks": "^3.4.2",
9694
"@testing-library/react-native": "^7.1.0",
97-
"@types/object-assign": "^4.0.30",
98-
"@types/react": "^18",
99-
"@types/react-dom": "^18",
100-
"@types/react-is": "^17",
95+
"@types/react": "^18.2.41",
96+
"@types/react-dom": "^18.2.17",
10197
"@types/react-native": "^0.67.4",
10298
"@typescript-eslint/eslint-plugin": "^4.28.0",
10399
"@typescript-eslint/parser": "^4.28.0",
104100
"babel-eslint": "^10.1.0",
105-
"babel-jest": "^26.6.1",
101+
"babel-jest": "^29",
106102
"codecov": "^3.8.0",
107103
"cross-env": "^7.0.2",
108104
"eslint": "^7.12.0",
@@ -111,20 +107,18 @@
111107
"eslint-plugin-prettier": "^3.1.4",
112108
"eslint-plugin-react": "^7.21.5",
113109
"glob": "^7.1.6",
114-
"jest": "^26.6.1",
110+
"jest": "^29",
111+
"jest-environment-jsdom": "^29.5.0",
112+
"metro-react-native-babel-preset": "^0.76.6",
115113
"prettier": "^2.1.2",
116-
"react": "18.0.0",
117-
"react-17": "npm:react@^17",
118-
"react-dom": "18.0.0",
119-
"react-dom-17": "npm:react-dom@^17",
120-
"react-native": "^0.64.1",
114+
"react": "18.2.0",
115+
"react-dom": "18.2.0",
116+
"react-native": "^0.71.11",
121117
"react-test-renderer": "18.0.0",
122-
"react-test-renderer-17": "npm:react-test-renderer@^17",
123-
"redux": "^4.0.5",
118+
"redux": "^5.0.0-beta.0",
124119
"rimraf": "^3.0.2",
125-
"rollup": "^2.32.1",
126-
"rollup-plugin-terser": "^7.0.2",
127-
"ts-jest": "26.5.6",
128-
"typescript": "^4.3.4"
120+
"ts-jest": "^29",
121+
"tsup": "^7.0.0",
122+
"typescript": "^5.0"
129123
}
130124
}

0 commit comments

Comments
 (0)