From 608805ad81c71276ee61c5679c1bdb63b48bc390 Mon Sep 17 00:00:00 2001 From: Anton Korzunov Date: Sat, 11 May 2019 16:01:43 +1000 Subject: [PATCH] fix: update root endpoint, fixes #1226, #1240 --- root.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/root.js b/root.js index 2fb4e85d1..756a9ea90 100644 --- a/root.js +++ b/root.js @@ -2,7 +2,7 @@ if (module.hot) { var hot = require('./index').hot; var cache = require.cache; - if (!module.parents || !module.parents[0]) { + if (!module.parents || module.parents.length === 0) { throw new Error( 'React-Hot-Loader: `react-hot-loader/root` is not supported on your system. ' + 'Please use `import {hot} from "react-hot-loader"` instead', @@ -10,11 +10,16 @@ if (module.hot) { } // access parent var parent = cache[module.parents[0]]; - // remove itself from a cache + if (!parent) { + throw new Error( + 'React-Hot-Loader: `react-hot-loader/root` is not supported on your system. ' + + 'Please use `import {hot} from "react-hot-loader"` instead', + ); + } + // remove self from a cache delete cache[module.id]; // setup hot for caller - - exports.hot = hot(Object.assign({ id: parent.i }, parent)); + exports.hot = hot(parent); } else { // prod mode exports.hot = function(a) {