Skip to content

Commit

Permalink
fix: handle the errorType which is overwrited
Browse files Browse the repository at this point in the history
  • Loading branch information
harrytothemoon authored Sep 8, 2022
1 parent f78252c commit 965683b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
21 changes: 12 additions & 9 deletions packages/error-overlay/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let stackTraceLimit: number | undefined = undefined;
let iframe: null | HTMLIFrameElement = null;
let isLoadingIframe: boolean = false;
let isIframeReady: boolean = false;
let errorType: errorTypeHandler.ErrorTypeEvent;
let errorTypeList: errorTypeHandler.ErrorTypeEvent[] = [];
let hasBuildError: Boolean = false;
let hasRuntimeError: Boolean = false;

Expand Down Expand Up @@ -45,11 +45,11 @@ function onUnhandledError(ev: ErrorEvent) {
}

hasRuntimeError = true;
errorType = {
errorTypeList.push({
type: TYPE_UNHANDLED_ERROR,
reason: error,
frames: parseStack(error.stack)
};
});
update();
}

Expand All @@ -65,11 +65,11 @@ function onUnhandledRejection(ev: PromiseRejectionEvent) {
}

hasRuntimeError = true;
errorType = {
errorTypeList.push({
type: TYPE_UNHANDLED_REJECTION,
reason: reason,
frames: parseStack(reason.stack)
};
});
update();
}

Expand Down Expand Up @@ -114,18 +114,18 @@ function stopReportingRuntimeErrors() {

function onBuildOk() {
hasBuildError = false;
errorType = { type: TYPE_BUILD_OK };
errorTypeList.push({ type: TYPE_BUILD_OK });
update();
}

function onBuildError(message: string) {
hasBuildError = true;
errorType = { type: TYPE_BUILD_ERROR, message };
errorTypeList.push({ type: TYPE_BUILD_ERROR, message });
update();
}

function onRefresh() {
errorType = { type: TYPE_REFRESH };
errorTypeList.push({ type: TYPE_REFRESH });
}

function applyStyles(element: HTMLElement, styles: Object) {
Expand Down Expand Up @@ -178,11 +178,14 @@ function updateIframeContent() {

//@ts-ignore
const isRendered = iframe.contentWindow!.updateContent({
errorType,
errorTypeList,
hasBuildError,
hasRuntimeError
});

//After the errors have been added to the queue of the error handler, we must clear the errorTypeList
errorTypeList = [];

if (!isRendered) {
window.document.body.removeChild(iframe);
iframe = null;
Expand Down
11 changes: 7 additions & 4 deletions packages/error-overlay/src/iframeScript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ let iframeRoot = null;
let errorBody = null;
let isFirstRender = true;

function render({ errorType, hasBuildError, hasRuntimeError }) {
errorTypeHandler.emit(errorType);
function render({ errorTypeList, hasBuildError, hasRuntimeError }) {
errorTypeList.forEach((errorType: errorTypeHandler.ErrorTypeEvent) => {
errorTypeHandler.emit(errorType);
});

if (!hasBuildError && !hasRuntimeError) {
return null;
}
return <ErrorOverlay />;
}

window.updateContent = function updateContent({
errorType,
errorTypeList,
hasBuildError,
hasRuntimeError
}) {
let renderedElement = render({
errorType,
errorTypeList,
hasBuildError,
hasRuntimeError
});
Expand Down

0 comments on commit 965683b

Please sign in to comment.