From 35e1656f3cca685925091c58d81bc5f749d99f3e Mon Sep 17 00:00:00 2001 From: Floris Bernard Date: Sat, 13 May 2017 13:20:28 +0200 Subject: [PATCH] Replace duplicate name error with console.warn When using hot module reloading, a new module will often be defined under the same name. In that case, we don't want to throw an error. Replace the error with a warning. --- .eslintrc | 1 + src/withInitAction.js | 2 +- tests/withInitAction.spec.js | 26 -------------------------- 3 files changed, 2 insertions(+), 27 deletions(-) diff --git a/.eslintrc b/.eslintrc index d7623d2..45b200b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -14,6 +14,7 @@ "react/jsx-filename-extension": 0, "linebreak-style": 0, "no-underscore-dangle": 0, + "no-console": 0, "import/first": "off", "import/order": ["error", { "groups": ["builtin", "external", "internal", "parent", "sibling", "index"], diff --git a/src/withInitAction.js b/src/withInitAction.js index cd63977..e5feafc 100644 --- a/src/withInitAction.js +++ b/src/withInitAction.js @@ -80,7 +80,7 @@ export default (p1, p2, p3) => { throw new Error('withInitAction() HoC requires the wrapped component to have a displayName'); } if (componentIds.includes(componentId)) { - throw new Error(`Each Component passed to withInitAction() should have a unique displayName. Found duplicate name "${componentId}"`); + console.warn(`Each Component passed to withInitAction() should have a unique displayName. Found duplicate name "${componentId}"`); } componentIds.push(componentId); diff --git a/tests/withInitAction.spec.js b/tests/withInitAction.spec.js index d7eb150..40dfe89 100644 --- a/tests/withInitAction.spec.js +++ b/tests/withInitAction.spec.js @@ -109,30 +109,4 @@ describe('withInitAction', () => { )(FooComponent); expect(WithInit.initConfig.initProps).toEqual(['a', 'b', 'c']); }); - - it('throws an error when two components with the same displayName are passed', () => { - clearComponentIds(); - class BarComponent extends Component { - render() { - return