Skip to content

Commit a6ba488

Browse files
committed
fix: make API more error prone, fixes #1228
1 parent 28bfdd4 commit a6ba488

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Diff for: src/hot.dev.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ const createHoc = (SourceComponent, TargetComponent) => {
2929
return TargetComponent;
3030
};
3131

32-
const makeHotExport = sourceModule => {
32+
const makeHotExport = (sourceModule, moduleId) => {
3333
const updateInstances = possibleError => {
3434
if (possibleError && possibleError instanceof Error) {
3535
console.error(possibleError);
3636
return;
3737
}
38-
const module = hotModule(sourceModule.id);
38+
const module = hotModule(moduleId);
3939
clearTimeout(module.updateTimeout);
4040
module.updateTimeout = setTimeout(() => {
4141
try {
42-
requireIndirect(sourceModule.id);
42+
requireIndirect(moduleId);
4343
} catch (e) {
44-
console.error('React-Hot-Loader: error detected while loading', sourceModule.id);
44+
console.error('React-Hot-Loader: error detected while loading', moduleId);
4545
console.error(e);
4646
}
4747
module.instances.forEach(inst => inst.forceUpdate());
@@ -68,16 +68,19 @@ const makeHotExport = sourceModule => {
6868
};
6969

7070
const hot = sourceModule => {
71-
if (!sourceModule || !sourceModule.id) {
71+
if (!sourceModule || !sourceModule.hot) {
7272
// this is fatal
73-
throw new Error('React-hot-loader: `hot` could not find the `id` property in the `module` you have provided');
73+
throw new Error('React-hot-loader: `hot` could not find the `hot` method in the `module` you have provided');
74+
}
75+
const moduleId = sourceModule.id || sourceModule.i || sourceModule.filename;
76+
if (!moduleId) {
77+
throw new Error('React-hot-loader: `hot` could not find the `name` of the the `module` you have provided');
7478
}
75-
const moduleId = sourceModule.id;
7679
const module = hotModule(moduleId);
77-
makeHotExport(sourceModule);
80+
makeHotExport(sourceModule, moduleId);
7881

7982
clearExceptions();
80-
const failbackTimer = chargeFailbackTimer(sourceModule.id);
83+
const failbackTimer = chargeFailbackTimer(moduleId);
8184
let firstHotRegistered = false;
8285

8386
// TODO: Ensure that all exports from this file are react components.

0 commit comments

Comments
 (0)