From 3806acc0031dbeddbc14fb00760df1c153ebdfd1 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 30 Jun 2021 10:02:23 -0400 Subject: [PATCH] Fixed timeout logic error in hook names cache --- .../react-devtools-shared/src/hookNamesCache.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/react-devtools-shared/src/hookNamesCache.js b/packages/react-devtools-shared/src/hookNamesCache.js index 99d2c13bc329f..dfb06950611b3 100644 --- a/packages/react-devtools-shared/src/hookNamesCache.js +++ b/packages/react-devtools-shared/src/hookNamesCache.js @@ -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 = (record = { status: Pending, value: wakeable, @@ -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; @@ -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);