Skip to content

Commit

Permalink
Revert the .catch() around Thenables in DevTools Suspense cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Sep 9, 2021
1 parent 7c8609d commit 3c3f072
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 63 deletions.
77 changes: 36 additions & 41 deletions packages/react-devtools-shared/src/hookNamesCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,51 +110,46 @@ export function loadHookNames(

let didTimeout = false;

const onSuccess = hookNames => {
if (didTimeout) {
return;
}

if (__DEBUG__) {
console.log('[hookNamesCache] onSuccess() hookNames:', hookNames);
}

if (hookNames) {
const resolvedRecord = ((newRecord: any): ResolvedRecord<HookNames>);
resolvedRecord.status = Resolved;
resolvedRecord.value = hookNames;
} else {
const notFoundRecord = ((newRecord: any): RejectedRecord);
notFoundRecord.status = Rejected;
notFoundRecord.value = null;
}

wake();
};

const onError = error => {
if (didTimeout) {
return;
}

if (__DEBUG__) {
console.log('[hookNamesCache] onError()');
}
loadHookNamesFunction(hooksTree, fetchFileWithCaching).then(
function onSuccess(hookNames) {
if (didTimeout) {
return;
}

if (__DEBUG__) {
console.log('[hookNamesCache] onSuccess() hookNames:', hookNames);
}

if (hookNames) {
const resolvedRecord = ((newRecord: any): ResolvedRecord<HookNames>);
resolvedRecord.status = Resolved;
resolvedRecord.value = hookNames;
} else {
const notFoundRecord = ((newRecord: any): RejectedRecord);
notFoundRecord.status = Rejected;
notFoundRecord.value = null;
}

wake();
},
function onError(error) {
if (didTimeout) {
return;
}

console.error(error);
if (__DEBUG__) {
console.log('[hookNamesCache] onError()');
}

const thrownRecord = ((newRecord: any): RejectedRecord);
thrownRecord.status = Rejected;
thrownRecord.value = null;
console.error(error);

wake();
};
const thrownRecord = ((newRecord: any): RejectedRecord);
thrownRecord.status = Rejected;
thrownRecord.value = null;

const thenable = loadHookNamesFunction(hooksTree, fetchFileWithCaching);
thenable.then(onSuccess, onError);
if (typeof (thenable: any).catch === 'function') {
(thenable: any).catch(onError);
}
wake();
},
);

// Eventually timeout and stop trying to load names.
let timeoutID = setTimeout(function onTimeout() {
Expand Down
40 changes: 18 additions & 22 deletions packages/react-devtools-shared/src/inspectedElementCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,34 +116,30 @@ export function inspectElement(
return null;
}

const onSuccess = ([inspectedElement: InspectedElementFrontend]) => {
const resolvedRecord = ((newRecord: any): ResolvedRecord<InspectedElementFrontend>);
resolvedRecord.status = Resolved;
resolvedRecord.value = inspectedElement;
wake();
};

const onError = error => {
if (newRecord.status === Pending) {
const rejectedRecord = ((newRecord: any): RejectedRecord);
rejectedRecord.status = Rejected;
rejectedRecord.value = `Could not inspect element with id "${element.id}". Error thrown:\n${error.message}`;
wake();
}
};

const thenable = inspectElementMutableSource({
inspectElementMutableSource({
bridge,
element,
path,
rendererID: ((rendererID: any): number),
});
thenable.then(onSuccess, onError);
}).then(
([inspectedElement: InspectedElementFrontend]) => {
const resolvedRecord = ((newRecord: any): ResolvedRecord<InspectedElementFrontend>);
resolvedRecord.status = Resolved;
resolvedRecord.value = inspectedElement;

if (typeof (thenable: any).catch === 'function') {
(thenable: any).catch();
}
wake();
},

error => {
console.error(error);

const rejectedRecord = ((newRecord: any): RejectedRecord);
rejectedRecord.status = Rejected;
rejectedRecord.value = `Could not inspect element with id "${element.id}". Error thrown:\n${error.message}`;

wake();
},
);
map.set(element, record);
}

Expand Down

0 comments on commit 3c3f072

Please sign in to comment.