@shuvi/error-overlay 1.0.0-rc.8 → 1.0.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +12 -1
- package/lib/iframe-bundle.js +12 -5
- package/lib/iframeScript.js +12 -5
- package/package.json +3 -3
- package/umd/index.js +13 -2
package/lib/client.js
CHANGED
|
@@ -13,6 +13,8 @@ let iframe = null;
|
|
|
13
13
|
let isLoadingIframe = false;
|
|
14
14
|
let isIframeReady = false;
|
|
15
15
|
let errorType;
|
|
16
|
+
let hasBuildError = false;
|
|
17
|
+
let hasRuntimeError = false;
|
|
16
18
|
const iframeStyle = {
|
|
17
19
|
position: 'fixed',
|
|
18
20
|
top: '0',
|
|
@@ -28,6 +30,7 @@ function onUnhandledError(ev) {
|
|
|
28
30
|
// A non-error was thrown, we don't have anything to show.
|
|
29
31
|
return;
|
|
30
32
|
}
|
|
33
|
+
hasRuntimeError = true;
|
|
31
34
|
errorType = {
|
|
32
35
|
type: constants_1.TYPE_UNHANDLED_ERROR,
|
|
33
36
|
reason: error,
|
|
@@ -43,6 +46,7 @@ function onUnhandledRejection(ev) {
|
|
|
43
46
|
// A non-error was thrown, we don't have anything to show.
|
|
44
47
|
return;
|
|
45
48
|
}
|
|
49
|
+
hasRuntimeError = true;
|
|
46
50
|
errorType = {
|
|
47
51
|
type: constants_1.TYPE_UNHANDLED_REJECTION,
|
|
48
52
|
reason: reason,
|
|
@@ -83,16 +87,19 @@ function stopReportingRuntimeErrors() {
|
|
|
83
87
|
catch (_a) { }
|
|
84
88
|
stackTraceLimit = undefined;
|
|
85
89
|
}
|
|
90
|
+
hasRuntimeError = false;
|
|
86
91
|
window.removeEventListener('error', onUnhandledError);
|
|
87
92
|
window.removeEventListener('unhandledrejection', onUnhandledRejection);
|
|
88
93
|
}
|
|
89
94
|
exports.stopReportingRuntimeErrors = stopReportingRuntimeErrors;
|
|
90
95
|
function onBuildOk() {
|
|
96
|
+
hasBuildError = false;
|
|
91
97
|
errorType = { type: constants_1.TYPE_BUILD_OK };
|
|
92
98
|
update();
|
|
93
99
|
}
|
|
94
100
|
exports.onBuildOk = onBuildOk;
|
|
95
101
|
function onBuildError(message) {
|
|
102
|
+
hasBuildError = true;
|
|
96
103
|
errorType = { type: constants_1.TYPE_BUILD_ERROR, message };
|
|
97
104
|
update();
|
|
98
105
|
}
|
|
@@ -146,7 +153,11 @@ function updateIframeContent() {
|
|
|
146
153
|
throw new Error('Iframe has not been created yet.');
|
|
147
154
|
}
|
|
148
155
|
//@ts-ignore
|
|
149
|
-
const isRendered = iframe.contentWindow.updateContent(
|
|
156
|
+
const isRendered = iframe.contentWindow.updateContent({
|
|
157
|
+
errorType,
|
|
158
|
+
hasBuildError,
|
|
159
|
+
hasRuntimeError
|
|
160
|
+
});
|
|
150
161
|
if (!isRendered) {
|
|
151
162
|
window.document.body.removeChild(iframe);
|
|
152
163
|
iframe = null;
|
package/lib/iframe-bundle.js
CHANGED
|
@@ -2603,14 +2603,21 @@ const ErrorOverlay = function ErrorOverlay() {
|
|
|
2603
2603
|
let iframeRoot = null;
|
|
2604
2604
|
let errorBody = null;
|
|
2605
2605
|
let isFirstRender = true;
|
|
2606
|
-
function render(
|
|
2607
|
-
emit(
|
|
2606
|
+
function render({ errorType, hasBuildError, hasRuntimeError }) {
|
|
2607
|
+
emit(errorType);
|
|
2608
|
+
if (!hasBuildError && !hasRuntimeError) {
|
|
2609
|
+
return null;
|
|
2610
|
+
}
|
|
2608
2611
|
return jsxRuntime.exports.jsx(ErrorOverlay, {});
|
|
2609
2612
|
}
|
|
2610
|
-
window.updateContent = function updateContent(
|
|
2611
|
-
let renderedElement = render(
|
|
2613
|
+
window.updateContent = function updateContent({ errorType, hasBuildError, hasRuntimeError }) {
|
|
2614
|
+
let renderedElement = render({
|
|
2615
|
+
errorType,
|
|
2616
|
+
hasBuildError,
|
|
2617
|
+
hasRuntimeError
|
|
2618
|
+
});
|
|
2612
2619
|
if (renderedElement === null) {
|
|
2613
|
-
errorBody.unmount();
|
|
2620
|
+
errorBody && errorBody.unmount();
|
|
2614
2621
|
return false;
|
|
2615
2622
|
}
|
|
2616
2623
|
// Update the overlay
|
package/lib/iframeScript.js
CHANGED
|
@@ -40,14 +40,21 @@ const errorTypeHandler = __importStar(require("./view/errorTypeHandler"));
|
|
|
40
40
|
let iframeRoot = null;
|
|
41
41
|
let errorBody = null;
|
|
42
42
|
let isFirstRender = true;
|
|
43
|
-
function render(
|
|
44
|
-
errorTypeHandler.emit(
|
|
43
|
+
function render({ errorType, hasBuildError, hasRuntimeError }) {
|
|
44
|
+
errorTypeHandler.emit(errorType);
|
|
45
|
+
if (!hasBuildError && !hasRuntimeError) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
45
48
|
return (0, jsx_runtime_1.jsx)(ErrorOverlay_1.ErrorOverlay, {});
|
|
46
49
|
}
|
|
47
|
-
window.updateContent = function updateContent(
|
|
48
|
-
let renderedElement = render(
|
|
50
|
+
window.updateContent = function updateContent({ errorType, hasBuildError, hasRuntimeError }) {
|
|
51
|
+
let renderedElement = render({
|
|
52
|
+
errorType,
|
|
53
|
+
hasBuildError,
|
|
54
|
+
hasRuntimeError
|
|
55
|
+
});
|
|
49
56
|
if (renderedElement === null) {
|
|
50
|
-
errorBody.unmount();
|
|
57
|
+
errorBody && errorBody.unmount();
|
|
51
58
|
return false;
|
|
52
59
|
}
|
|
53
60
|
// Update the overlay
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/error-overlay",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.9",
|
|
4
4
|
"main": "umd/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@babel/code-frame": "7.14.5",
|
|
25
|
-
"@shuvi/shared": "1.0.0-rc.
|
|
26
|
-
"@shuvi/toolpack": "1.0.0-rc.
|
|
25
|
+
"@shuvi/shared": "1.0.0-rc.9",
|
|
26
|
+
"@shuvi/toolpack": "1.0.0-rc.9",
|
|
27
27
|
"anser": "1.4.9",
|
|
28
28
|
"data-uri-to-buffer": "3.0.1",
|
|
29
29
|
"html-entities": "2.3.2",
|