Skip to content

Commit

Permalink
Fixed timeout logic error in hook names cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Jun 30, 2021
1 parent 21d886f commit 3806acc
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/react-devtools-shared/src/hookNamesCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,18 @@ export function loadHookNames(
callbacks.add(callback);
},
};

const wake = () => {
if (timeoutID) {
clearTimeout(timeoutID);
timeoutID = null;
}

// This assumes they won't throw.
callbacks.forEach(callback => callback());
callbacks.clear();
};

const newRecord: Record<HookNames> = (record = {
status: Pending,
value: wakeable,
Expand All @@ -113,6 +120,10 @@ export function loadHookNames(
wake();
},
function onError(error) {
if (didTimeout) {
return;
}

const thrownRecord = ((newRecord: any): RejectedRecord);
thrownRecord.status = Rejected;
thrownRecord.value = null;
Expand All @@ -122,7 +133,9 @@ export function loadHookNames(
);

// Eventually timeout and stop trying to load names.
setTimeout(() => {
let timeoutID = setTimeout(() => {
timeoutID = null;

didTimeout = true;

const timedoutRecord = ((newRecord: any): RejectedRecord);
Expand Down

0 comments on commit 3806acc

Please sign in to comment.