Skip to content

Commit 9ed9917

Browse files
authored
Merge pull request reduxjs#3920 from andrewmcgivery/master
Former-commit-id: 756ba19
2 parents fe1b1f5 + 16d8a76 commit 9ed9917

10 files changed

+167
-34
lines changed

errors.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"0": "It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function.",
3+
"1": "Expected the enhancer to be a function.",
4+
"2": "Expected the reducer to be a function.",
5+
"3": "You may not call store.getState() while the reducer is executing. The reducer has already received the state as an argument. Pass it down from the top reducer instead of reading it from the store.",
6+
"4": "Expected the listener to be a function.",
7+
"5": "You may not call store.subscribe() while the reducer is executing. If you would like to be notified after the store has been updated, subscribe from a component and invoke store.getState() in the callback to access the latest state. See https://redux.js.org/api/store#subscribelistener for more details.",
8+
"6": "You may not unsubscribe from a store listener while the reducer is executing. See https://redux.js.org/api/store#subscribelistener for more details.",
9+
"7": "Actions must be plain objects. Use custom middleware for async actions.",
10+
"8": "Actions may not have an undefined \"type\" property. Have you misspelled a constant?",
11+
"9": "Reducers may not dispatch actions.",
12+
"10": "Expected the nextReducer to be a function.",
13+
"11": "Expected the observer to be an object.",
14+
"12": "bindActionCreators expected an object or a function, instead received . Did you write \"import ActionCreators from\" instead of \"import * as ActionCreators from\"?",
15+
"13": "Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.",
16+
"14": "Reducer \"\" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.",
17+
"15": "Reducer \"\" returned undefined when probed with a random type. Don't try to handle or other actions in \"redux/*\" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined, but can be null.",
18+
"16": "Super expression must either be null or a function"
19+
}

package-lock.json.REMOVED.git-id

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@babel/preset-flow": "^7.9.0",
6464
"@babel/preset-typescript": "^7.9.0",
6565
"@babel/register": "^7.9.0",
66-
"@rollup/plugin-babel": "^5.2.2",
66+
"@rollup/plugin-babel": "^5.3.0",
6767
"@rollup/plugin-node-resolve": "^7.1.3",
6868
"@rollup/plugin-replace": "^2.3.2",
6969
"@types/jest": "^25.2.1",

rollup.config.js

+37-30
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ const babelRuntimeVersion = pkg.dependencies['@babel/runtime'].replace(
1414
''
1515
)
1616

17-
const makeExternalPredicate = (externalArr) => {
17+
const makeExternalPredicate = externalArr => {
1818
if (externalArr.length === 0) {
1919
return () => false
2020
}
2121
const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`)
22-
return (id) => pattern.test(id)
22+
return id => pattern.test(id)
2323
}
2424

2525
export default [
@@ -29,21 +29,22 @@ export default [
2929
output: { file: 'lib/redux.js', format: 'cjs', indent: false },
3030
external: makeExternalPredicate([
3131
...Object.keys(pkg.dependencies || {}),
32-
...Object.keys(pkg.peerDependencies || {}),
32+
...Object.keys(pkg.peerDependencies || {})
3333
]),
3434
plugins: [
3535
nodeResolve({
36-
extensions,
36+
extensions
3737
}),
3838
typescript({ useTsconfigDeclarationDir: true }),
3939
babel({
4040
extensions,
4141
plugins: [
4242
['@babel/plugin-transform-runtime', { version: babelRuntimeVersion }],
43+
['./scripts/mangleErrors.js', { minify: false }]
4344
],
4445
babelHelpers: 'runtime'
45-
}),
46-
],
46+
})
47+
]
4748
},
4849

4950
// ES
@@ -52,24 +53,25 @@ export default [
5253
output: { file: 'es/redux.js', format: 'es', indent: false },
5354
external: makeExternalPredicate([
5455
...Object.keys(pkg.dependencies || {}),
55-
...Object.keys(pkg.peerDependencies || {}),
56+
...Object.keys(pkg.peerDependencies || {})
5657
]),
5758
plugins: [
5859
nodeResolve({
59-
extensions,
60+
extensions
6061
}),
6162
typescript({ tsconfigOverride: noDeclarationFiles }),
6263
babel({
6364
extensions,
6465
plugins: [
6566
[
6667
'@babel/plugin-transform-runtime',
67-
{ version: babelRuntimeVersion, useESModules: true },
68+
{ version: babelRuntimeVersion, useESModules: true }
6869
],
70+
['./scripts/mangleErrors.js', { minify: false }]
6971
],
7072
babelHelpers: 'runtime'
71-
}),
72-
],
73+
})
74+
]
7375
},
7476

7577
// ES for Browsers
@@ -78,25 +80,27 @@ export default [
7880
output: { file: 'es/redux.mjs', format: 'es', indent: false },
7981
plugins: [
8082
nodeResolve({
81-
extensions,
83+
extensions
8284
}),
8385
replace({
84-
'process.env.NODE_ENV': JSON.stringify('production'),
86+
'process.env.NODE_ENV': JSON.stringify('production')
8587
}),
8688
typescript({ tsconfigOverride: noDeclarationFiles }),
8789
babel({
8890
extensions,
8991
exclude: 'node_modules/**',
92+
plugins: [['./scripts/mangleErrors.js', { minify: true }]],
93+
skipPreflightCheck: true
9094
}),
9195
terser({
9296
compress: {
9397
pure_getters: true,
9498
unsafe: true,
9599
unsafe_comps: true,
96-
warnings: false,
97-
},
98-
}),
99-
],
100+
warnings: false
101+
}
102+
})
103+
]
100104
},
101105

102106
// UMD Development
@@ -106,21 +110,22 @@ export default [
106110
file: 'dist/redux.js',
107111
format: 'umd',
108112
name: 'Redux',
109-
indent: false,
113+
indent: false
110114
},
111115
plugins: [
112116
nodeResolve({
113-
extensions,
117+
extensions
114118
}),
115119
typescript({ tsconfigOverride: noDeclarationFiles }),
116120
babel({
117121
extensions,
118122
exclude: 'node_modules/**',
123+
plugins: [['./scripts/mangleErrors.js', { minify: false }]]
119124
}),
120125
replace({
121-
'process.env.NODE_ENV': JSON.stringify('development'),
122-
}),
123-
],
126+
'process.env.NODE_ENV': JSON.stringify('development')
127+
})
128+
]
124129
},
125130

126131
// UMD Production
@@ -130,28 +135,30 @@ export default [
130135
file: 'dist/redux.min.js',
131136
format: 'umd',
132137
name: 'Redux',
133-
indent: false,
138+
indent: false
134139
},
135140
plugins: [
136141
nodeResolve({
137-
extensions,
142+
extensions
138143
}),
139144
typescript({ tsconfigOverride: noDeclarationFiles }),
140145
babel({
141146
extensions,
142147
exclude: 'node_modules/**',
148+
plugins: [['./scripts/mangleErrors.js', { minify: true }]],
149+
skipPreflightCheck: true
143150
}),
144151
replace({
145-
'process.env.NODE_ENV': JSON.stringify('production'),
152+
'process.env.NODE_ENV': JSON.stringify('production')
146153
}),
147154
terser({
148155
compress: {
149156
pure_getters: true,
150157
unsafe: true,
151158
unsafe_comps: true,
152-
warnings: false,
153-
},
154-
}),
155-
],
156-
},
159+
warnings: false
160+
}
161+
})
162+
]
163+
}
157164
]
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d8b8502a52b248ac7e5ebc22f33a4763e05af8b2

src/utils/formatProdErrorMessage.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js
3+
*
4+
* Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes
5+
* during build.
6+
* @param {number} code
7+
*/
8+
function formatProdErrorMessage(code: number) {
9+
return (
10+
`Minified Redux error #${code}; visit https://redux.js.org/Errors?code=${code} for the full message or ` +
11+
'use the non-minified dev environment for full errors. '
12+
)
13+
}
14+
15+
export default formatProdErrorMessage

website/package-lock.json.REMOVED.git-id

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"@docusaurus/preset-classic": "2.0.0-alpha.70",
1111
"classnames": "2.2.6",
1212
"react": "16.13.0",
13-
"react-dom": "16.13.0"
13+
"react-dom": "16.13.0",
14+
"url-search-params-polyfill": "^8.1.0"
1415
},
1516
"browserslist": {
1617
"production": [

website/src/pages/errors.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React from 'react'
2+
import Layout from '@theme/Layout'
3+
import { useLocation } from '@docusaurus/router'
4+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'
5+
import styles from './styles.module.css'
6+
import errorCodes from '../../../errors.json'
7+
import 'url-search-params-polyfill'
8+
9+
function Errors() {
10+
const location = useLocation()
11+
const context = useDocusaurusContext()
12+
const { siteConfig = {} } = context
13+
const errorCode = new URLSearchParams(location.search).get('code')
14+
const error = errorCodes[errorCode]
15+
16+
return (
17+
<Layout
18+
title={`${siteConfig.title} - A predictable state container for JavaScript apps.`}
19+
description="A predictable state container for JavaScript apps."
20+
>
21+
<main className={styles.mainFull}>
22+
<h1>Production Error Codes</h1>
23+
<p>
24+
When Redux is built and running in production, error text is replaced
25+
by indexed error codes to save on bundle size. These errors will
26+
provide a link to this page with more information about the error
27+
below.
28+
</p>
29+
{error && (
30+
<React.Fragment>
31+
<p>
32+
<strong>
33+
The full text of the error you just encountered is:
34+
</strong>
35+
</p>
36+
<code className={styles.errorDetails}>{error}</code>
37+
</React.Fragment>
38+
)}
39+
40+
<h2>All Error Codes</h2>
41+
<table>
42+
<thead>
43+
<tr>
44+
<th>Code</th>
45+
<th>Message</th>
46+
</tr>
47+
</thead>
48+
<tbody>
49+
{Object.keys(errorCodes).map(code => (
50+
<tr>
51+
<td>{code}</td>
52+
<td>{errorCodes[code]}</td>
53+
</tr>
54+
))}
55+
</tbody>
56+
</table>
57+
</main>
58+
</Layout>
59+
)
60+
}
61+
62+
export default Errors

website/src/pages/styles.module.css

+28
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,31 @@
4141
max-height: 16px;
4242
fill: var(--ifm-color-primary);
4343
}
44+
45+
.mainFull {
46+
padding: 34px 16px;
47+
width: 100%;
48+
max-width: var(--ifm-container-width);
49+
margin: 0px auto;
50+
}
51+
.mainFull h1 {
52+
font-size: 3rem;
53+
color: var(--ifm-heading-color);
54+
font-weight: var(--ifm-heading-font-weight);
55+
line-height: var(--ifm-heading-line-height);
56+
}
57+
58+
.mainFull p {
59+
margin-bottom: var(--ifm-leading);
60+
margin-top: 0;
61+
}
62+
63+
.errorDetails {
64+
color: #ff6464;
65+
border-radius: 0.5rem;
66+
padding: 1rem;
67+
margin: 30px 0;
68+
font-weight: bold;
69+
background-color: rgba(255, 100, 100, 0.1);
70+
display: block;
71+
}

0 commit comments

Comments
 (0)