Skip to content

Commit c019663

Browse files
committed
fix: error overlay should not be injected into the first instance, fixes #1337
1 parent 941b41c commit c019663

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/global/generation.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ let generation = 1;
77
// these counters are aimed to mitigate the "first render"
88
let hotComparisonCounter = 0;
99
let hotComparisonRuns = 0;
10+
let hotReplacementGeneration = 0;
11+
1012
const nullFunction = () => ({});
1113

1214
// these callbacks would be called on component update
@@ -24,7 +26,8 @@ export const setComparisonHooks = (open, element, close) => {
2426
export const getElementComparisonHook = component => onHotComparisonElement(component);
2527
export const getElementCloseHook = component => onHotComparisonClose(component);
2628

27-
export const hotComparisonOpen = () => hotComparisonCounter > 0 && hotComparisonRuns > 0;
29+
export const hotComparisonOpen = () =>
30+
hotComparisonCounter > 0 && hotComparisonRuns > 0 && hotReplacementGeneration > 0;
2831

2932
const openGeneration = () => forEachKnownClass(onHotComparisonElement);
3033

@@ -48,6 +51,7 @@ const decrementHot = () => {
4851
export const configureGeneration = (counter, runs) => {
4952
hotComparisonCounter = counter;
5053
hotComparisonRuns = runs;
54+
hotReplacementGeneration = runs;
5155
};
5256

5357
// TODO: shall it be called from incrementHotGeneration?
@@ -63,6 +67,5 @@ export const increment = () => {
6367
export const get = () => generation;
6468

6569
// These counters tracks HMR generations, and probably should be used instead of the old one
66-
let hotReplacementGeneration = 0;
6770
export const incrementHotGeneration = () => hotReplacementGeneration++;
6871
export const getHotGeneration = () => hotReplacementGeneration;

src/utils/runQueue.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const createQueue = (runner = a => a()) => {
2+
let promise;
3+
let queue = [];
4+
5+
const runAll = () => {
6+
const oldQueue = queue;
7+
oldQueue.forEach(cb => cb());
8+
queue = [];
9+
};
10+
11+
const add = cb => {
12+
if (queue.length === 0) {
13+
promise = Promise.resolve().then(() => runner(runAll()));
14+
}
15+
queue.push(cb);
16+
17+
return promise;
18+
};
19+
20+
return add;
21+
};

0 commit comments

Comments
 (0)