Skip to content

Commit 3806acc

Browse files
author
Brian Vaughn
committed
Fixed timeout logic error in hook names cache
1 parent 21d886f commit 3806acc

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/react-devtools-shared/src/hookNamesCache.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,18 @@ export function loadHookNames(
8282
callbacks.add(callback);
8383
},
8484
};
85+
8586
const wake = () => {
87+
if (timeoutID) {
88+
clearTimeout(timeoutID);
89+
timeoutID = null;
90+
}
91+
8692
// This assumes they won't throw.
8793
callbacks.forEach(callback => callback());
8894
callbacks.clear();
8995
};
96+
9097
const newRecord: Record<HookNames> = (record = {
9198
status: Pending,
9299
value: wakeable,
@@ -113,6 +120,10 @@ export function loadHookNames(
113120
wake();
114121
},
115122
function onError(error) {
123+
if (didTimeout) {
124+
return;
125+
}
126+
116127
const thrownRecord = ((newRecord: any): RejectedRecord);
117128
thrownRecord.status = Rejected;
118129
thrownRecord.value = null;
@@ -122,7 +133,9 @@ export function loadHookNames(
122133
);
123134

124135
// Eventually timeout and stop trying to load names.
125-
setTimeout(() => {
136+
let timeoutID = setTimeout(() => {
137+
timeoutID = null;
138+
126139
didTimeout = true;
127140

128141
const timedoutRecord = ((newRecord: any): RejectedRecord);

0 commit comments

Comments
 (0)