diff --git a/errors.json b/errors.json new file mode 100644 index 00000000000..2fac82d961e --- /dev/null +++ b/errors.json @@ -0,0 +1,19 @@ +{ + "0": "It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function. See https://redux.js.org/tutorials/fundamentals/part-4-store#creating-a-store-with-enhancers for an example.", + "1": "Expected the enhancer to be a function. Instead, received: ''", + "2": "Expected the root reducer to be a function. Instead, received: ''", + "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.", + "4": "Expected the listener to be a function. Instead, received: ''", + "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.", + "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.", + "7": "Actions must be plain objects. Instead, the actual type was: ''. You may need to add middleware to your store setup to handle dispatching other values, such as 'redux-thunk' to handle dispatching functions. See https://redux.js.org/tutorials/fundamentals/part-4-store#middleware and https://redux.js.org/tutorials/fundamentals/part-6-async-logic#using-the-redux-thunk-middleware for examples.", + "8": "Actions may not have an undefined \"type\" property. You may have misspelled an action type string constant.", + "9": "Reducers may not dispatch actions.", + "10": "Expected the nextReducer to be a function. Instead, received: '", + "11": "Expected the observer to be an object. Instead, received: ''", + "12": "The slice reducer for key \"\" 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.", + "13": "The slice reducer for key \"\" 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.", + "14": "When called with an action of type , the slice reducer for key \"\" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.", + "15": "Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.", + "16": "bindActionCreators expected an object or a function, but instead received: ''. Did you write \"import ActionCreators from\" instead of \"import * as ActionCreators from\"?" +} \ No newline at end of file diff --git a/rollup.config.js b/rollup.config.js index 9a32e514792..90af2fd2beb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -37,6 +37,7 @@ export default [ extensions, plugins: [ ['@babel/plugin-transform-runtime', { version: babelRuntimeVersion }], + ['./scripts/mangleErrors.js', { minify: false }] ], babelHelpers: 'runtime' }) @@ -62,6 +63,7 @@ export default [ '@babel/plugin-transform-runtime', { version: babelRuntimeVersion, useESModules: true } ], + ['./scripts/mangleErrors.js', { minify: false }] ], babelHelpers: 'runtime' }) @@ -82,6 +84,7 @@ export default [ babel({ extensions, exclude: 'node_modules/**', + plugins: [['./scripts/mangleErrors.js', { minify: true }]], skipPreflightCheck: true }), terser({ @@ -111,6 +114,7 @@ export default [ babel({ extensions, exclude: 'node_modules/**', + plugins: [['./scripts/mangleErrors.js', { minify: false }]] }), replace({ 'process.env.NODE_ENV': JSON.stringify('development') @@ -134,6 +138,7 @@ export default [ babel({ extensions, exclude: 'node_modules/**', + plugins: [['./scripts/mangleErrors.js', { minify: true }]], skipPreflightCheck: true }), replace({ diff --git a/scripts/mangleErrors.js.REMOVED.git-id b/scripts/mangleErrors.js.REMOVED.git-id new file mode 100644 index 00000000000..eb1e5c44a41 --- /dev/null +++ b/scripts/mangleErrors.js.REMOVED.git-id @@ -0,0 +1 @@ +fcd7e7391da1cb7ac4a9fb471298f91474f47043 \ No newline at end of file diff --git a/src/bindActionCreators.js b/src/bindActionCreators.js index dd78819e561..8e610e85720 100644 --- a/src/bindActionCreators.js +++ b/src/bindActionCreators.js @@ -1,3 +1,5 @@ +import { kindOf } from './utils/kindOf' + function bindActionCreator(actionCreator, dispatch) { return function () { return dispatch(actionCreator.apply(this, arguments)) @@ -32,9 +34,9 @@ export default function bindActionCreators(actionCreators, dispatch) { if (typeof actionCreators !== 'object' || actionCreators === null) { throw new Error( - `bindActionCreators expected an object or a function, instead received ${ - actionCreators === null ? 'null' : typeof actionCreators - }. ` + + `bindActionCreators expected an object or a function, but instead received: '${kindOf( + actionCreators + )}'. ` + `Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?` ) } diff --git a/src/combineReducers.js.REMOVED.git-id b/src/combineReducers.js.REMOVED.git-id index b64e3f74b26..af026189f33 100644 --- a/src/combineReducers.js.REMOVED.git-id +++ b/src/combineReducers.js.REMOVED.git-id @@ -1 +1 @@ -dcf06f2829ebc3ab3c0c9f85735e81e32b36eeb6 \ No newline at end of file +6ed79c245ca26e73bacd6cd91db6ddb0d1104c51 \ No newline at end of file diff --git a/src/createStore.js.REMOVED.git-id b/src/createStore.js.REMOVED.git-id index 190a92a4a78..49811b6b9f2 100644 --- a/src/createStore.js.REMOVED.git-id +++ b/src/createStore.js.REMOVED.git-id @@ -1 +1 @@ -45b09aca009a5a9a2298800982c77b87e45b47ab \ No newline at end of file +5326a52ff8a82cca2a564d2f5b6eaf16396411f7 \ No newline at end of file diff --git a/src/utils/formatProdErrorMessage.js b/src/utils/formatProdErrorMessage.js new file mode 100644 index 00000000000..3ae0234656b --- /dev/null +++ b/src/utils/formatProdErrorMessage.js @@ -0,0 +1,15 @@ +/** + * Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js + * + * Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes + * during build. + * @param {number} code + */ +function formatProdErrorMessage(code) { + return ( + `Minified Redux error #${code}; visit https://redux.js.org/Errors?code=${code} for the full message or ` + + 'use the non-minified dev environment for full errors. ' + ) +} + +export default formatProdErrorMessage diff --git a/src/utils/kindOf.js b/src/utils/kindOf.js new file mode 100644 index 00000000000..c5395a1df6b --- /dev/null +++ b/src/utils/kindOf.js @@ -0,0 +1,70 @@ +export function kindOf(val) { + let typeOfVal = typeof val + + if (process.env.NODE_ENV !== 'production') { + // Inlined / shortened version of `kindOf` from https://github.com/jonschlinkert/kind-of + function miniKindOf(val) { + if (val === void 0) return 'undefined' + if (val === null) return 'null' + + const type = typeof val + switch (type) { + case 'boolean': + case 'string': + case 'number': + case 'symbol': + case 'function': { + return type + } + default: + break + } + + if (Array.isArray(val)) return 'array' + if (isDate(val)) return 'date' + if (isError(val)) return 'error' + + const constructorName = ctorName(val) + switch (constructorName) { + case 'Symbol': + case 'Promise': + case 'WeakMap': + case 'WeakSet': + case 'Map': + case 'Set': + return constructorName + default: + break + } + + // other + return type.slice(8, -1).toLowerCase().replace(/\s/g, '') + } + + function ctorName(val) { + return typeof val.constructor === 'function' ? val.constructor.name : null + } + + function isError(val) { + return ( + val instanceof Error || + (typeof val.message === 'string' && + val.constructor && + typeof val.constructor.stackTraceLimit === 'number') + ) + } + + function isDate(val) { + if (val instanceof Date) return true + return ( + typeof val.toDateString === 'function' && + typeof val.getDate === 'function' && + typeof val.setDate === 'function' + ) + } + + typeOfVal = miniKindOf(val) + } + + return typeOfVal +} diff --git a/test/bindActionCreators.spec.js b/test/bindActionCreators.spec.js index 54031dbbeef..1cebddb13e6 100644 --- a/test/bindActionCreators.spec.js +++ b/test/bindActionCreators.spec.js @@ -75,8 +75,8 @@ describe('bindActionCreators', () => { expect(() => { bindActionCreators(undefined, store.dispatch) }).toThrow( - 'bindActionCreators expected an object or a function, instead received undefined. ' + - 'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?' + `bindActionCreators expected an object or a function, but instead received: 'undefined'. ` + + `Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?` ) }) @@ -84,8 +84,8 @@ describe('bindActionCreators', () => { expect(() => { bindActionCreators(null, store.dispatch) }).toThrow( - 'bindActionCreators expected an object or a function, instead received null. ' + - 'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?' + `bindActionCreators expected an object or a function, but instead received: 'null'. ` + + `Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?` ) }) @@ -93,8 +93,8 @@ describe('bindActionCreators', () => { expect(() => { bindActionCreators('string', store.dispatch) }).toThrow( - 'bindActionCreators expected an object or a function, instead received string. ' + - 'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?' + `bindActionCreators expected an object or a function, but instead received: 'string'. ` + + `Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?` ) }) }) diff --git a/test/combineReducers.spec.js.REMOVED.git-id b/test/combineReducers.spec.js.REMOVED.git-id index 52d8d7ef331..da65a1f691e 100644 --- a/test/combineReducers.spec.js.REMOVED.git-id +++ b/test/combineReducers.spec.js.REMOVED.git-id @@ -1 +1 @@ -cfd712da380142f8aba47f37add1db132a57febf \ No newline at end of file +a72c1541dd446692cf3bc2496e99a838f4ea93c2 \ No newline at end of file diff --git a/test/createStore.spec.js.REMOVED.git-id b/test/createStore.spec.js.REMOVED.git-id index 88a67193fa8..bbff797d2c4 100644 --- a/test/createStore.spec.js.REMOVED.git-id +++ b/test/createStore.spec.js.REMOVED.git-id @@ -1 +1 @@ -9bbac18428e62d57a68306a56c5e17ce6e55f13d \ No newline at end of file +dcbf65cf3e5d3da0bf7bd0a1934b8951120f395c \ No newline at end of file