@shuvi/error-overlay 1.0.26 → 1.0.28

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 CHANGED
@@ -92,6 +92,10 @@ function stopReportingRuntimeErrors() {
92
92
  window.removeEventListener('unhandledrejection', onUnhandledRejection);
93
93
  }
94
94
  exports.stopReportingRuntimeErrors = stopReportingRuntimeErrors;
95
+ function dismissRuntimeErrors() {
96
+ hasRuntimeError = false;
97
+ update();
98
+ }
95
99
  function onBuildOk() {
96
100
  hasBuildError = false;
97
101
  errorTypeList.push({ type: constants_1.TYPE_BUILD_OK });
@@ -148,7 +152,6 @@ function update() {
148
152
  const appDocument = window.document;
149
153
  appDocument.body.appendChild(loadingIframe);
150
154
  }
151
- let prevRendered = false;
152
155
  function updateIframeContent() {
153
156
  if (!iframe) {
154
157
  throw new Error('Iframe has not been created yet.');
@@ -157,17 +160,16 @@ function updateIframeContent() {
157
160
  const isRendered = iframe.contentWindow.updateContent({
158
161
  errorTypeList,
159
162
  hasBuildError,
160
- hasRuntimeError
163
+ hasRuntimeError,
164
+ dismissRuntimeErrors
161
165
  });
162
166
  //After the errors have been added to the queue of the error handler, we must clear the errorTypeList
163
167
  errorTypeList = [];
164
- // Continuous errors and no errors will not operate dom
165
- if (prevRendered && !isRendered) {
168
+ if (!isRendered) {
166
169
  window.document.body.removeChild(iframe);
167
170
  iframe = null;
168
171
  isIframeReady = false;
169
172
  }
170
- prevRendered = isRendered;
171
173
  }
172
174
  window.__SHUVI_ERROR_OVERLAY_GLOBAL_HOOK__ =
173
175
  window.__SHUVI_ERROR_OVERLAY_GLOBAL_HOOK__ || {};
@@ -3248,7 +3248,7 @@
3248
3248
  }
3249
3249
  return '';
3250
3250
  }
3251
- const RuntimeError$1 = function RuntimeError({ errors }) {
3251
+ const RuntimeError$1 = function RuntimeError({ errors, close }) {
3252
3252
  const [lookups, setLookups] = React.useState({});
3253
3253
  const [readyErrors, nextError] = React.useMemo(() => {
3254
3254
  let ready = [];
@@ -3307,6 +3307,7 @@
3307
3307
  const minimize = React.useCallback((e) => {
3308
3308
  e === null || e === void 0 ? void 0 : e.preventDefault();
3309
3309
  setDisplayState('minimized');
3310
+ close();
3310
3311
  }, []);
3311
3312
  const hide = React.useCallback((e) => {
3312
3313
  e === null || e === void 0 ? void 0 : e.preventDefault();
@@ -3953,7 +3954,7 @@
3953
3954
  }
3954
3955
  }
3955
3956
  }
3956
- const ErrorOverlay$1 = function ErrorOverlay() {
3957
+ const ErrorOverlay$1 = function ErrorOverlay({ dismissRuntimeErrors }) {
3957
3958
  const [state, dispatch] = React.useReducer(reducer, {
3958
3959
  nextId: 1,
3959
3960
  buildError: null,
@@ -3968,7 +3969,7 @@
3968
3969
  const hasBuildError = state.buildError != null;
3969
3970
  const hasRuntimeErrors = Boolean(state.errors.length);
3970
3971
  const isMounted = hasBuildError || hasRuntimeErrors;
3971
- return ((0, jsx_runtime_1.jsx)(React.Fragment, { children: isMounted ? ((0, jsx_runtime_1.jsxs)(ShadowPortal_1.ShadowPortal, { children: [(0, jsx_runtime_1.jsx)(CssReset_1.CssReset, {}), (0, jsx_runtime_1.jsx)(Base_1.Base, {}), (0, jsx_runtime_1.jsx)(ComponentStyles_1.ComponentStyles, {}), hasBuildError ? ((0, jsx_runtime_1.jsx)(BuildError_1.BuildError, { error: state.buildError })) : hasRuntimeErrors ? ((0, jsx_runtime_1.jsx)(RuntimeError_1.RuntimeError, { errors: state.errors })) : undefined] })) : undefined }));
3972
+ return ((0, jsx_runtime_1.jsx)(React.Fragment, { children: isMounted ? ((0, jsx_runtime_1.jsxs)(ShadowPortal_1.ShadowPortal, { children: [(0, jsx_runtime_1.jsx)(CssReset_1.CssReset, {}), (0, jsx_runtime_1.jsx)(Base_1.Base, {}), (0, jsx_runtime_1.jsx)(ComponentStyles_1.ComponentStyles, {}), hasBuildError ? ((0, jsx_runtime_1.jsx)(BuildError_1.BuildError, { error: state.buildError })) : hasRuntimeErrors ? ((0, jsx_runtime_1.jsx)(RuntimeError_1.RuntimeError, { errors: state.errors, close: dismissRuntimeErrors })) : undefined] })) : undefined }));
3972
3973
  };
3973
3974
  ErrorOverlay.ErrorOverlay = ErrorOverlay$1;
3974
3975
 
@@ -3991,20 +3992,21 @@
3991
3992
  let iframeRoot = null;
3992
3993
  let errorBody = null;
3993
3994
  let isFirstRender = true;
3994
- function render({ errorTypeList, hasBuildError, hasRuntimeError }) {
3995
+ function render({ errorTypeList, hasBuildError, hasRuntimeError, dismissRuntimeErrors }) {
3995
3996
  errorTypeList.forEach((errorType) => {
3996
3997
  errorTypeHandler.emit(errorType);
3997
3998
  });
3998
3999
  if (!hasBuildError && !hasRuntimeError) {
3999
4000
  return null;
4000
4001
  }
4001
- return (0, jsx_runtime_1.jsx)(ErrorOverlay_1.ErrorOverlay, {});
4002
+ return (0, jsx_runtime_1.jsx)(ErrorOverlay_1.ErrorOverlay, { dismissRuntimeErrors: dismissRuntimeErrors });
4002
4003
  }
4003
- window.updateContent = function updateContent({ errorTypeList, hasBuildError, hasRuntimeError }) {
4004
+ window.updateContent = function updateContent({ errorTypeList, hasBuildError, hasRuntimeError, dismissRuntimeErrors }) {
4004
4005
  let renderedElement = render({
4005
4006
  errorTypeList,
4006
4007
  hasBuildError,
4007
- hasRuntimeError
4008
+ hasRuntimeError,
4009
+ dismissRuntimeErrors
4008
4010
  });
4009
4011
  if (renderedElement === null) {
4010
4012
  errorBody && errorBody.unmount();
@@ -40,20 +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({ errorTypeList, hasBuildError, hasRuntimeError }) {
43
+ function render({ errorTypeList, hasBuildError, hasRuntimeError, dismissRuntimeErrors }) {
44
44
  errorTypeList.forEach((errorType) => {
45
45
  errorTypeHandler.emit(errorType);
46
46
  });
47
47
  if (!hasBuildError && !hasRuntimeError) {
48
48
  return null;
49
49
  }
50
- return (0, jsx_runtime_1.jsx)(ErrorOverlay_1.ErrorOverlay, {});
50
+ return (0, jsx_runtime_1.jsx)(ErrorOverlay_1.ErrorOverlay, { dismissRuntimeErrors: dismissRuntimeErrors });
51
51
  }
52
- window.updateContent = function updateContent({ errorTypeList, hasBuildError, hasRuntimeError }) {
52
+ window.updateContent = function updateContent({ errorTypeList, hasBuildError, hasRuntimeError, dismissRuntimeErrors }) {
53
53
  let renderedElement = render({
54
54
  errorTypeList,
55
55
  hasBuildError,
56
- hasRuntimeError
56
+ hasRuntimeError,
57
+ dismissRuntimeErrors
57
58
  });
58
59
  if (renderedElement === null) {
59
60
  errorBody && errorBody.unmount();
@@ -1,2 +1,5 @@
1
- /// <reference types="react" />
2
- export declare const ErrorOverlay: () => JSX.Element;
1
+ import * as React from 'react';
2
+ export declare type ErrorOverlayProps = {
3
+ dismissRuntimeErrors: () => void;
4
+ };
5
+ export declare const ErrorOverlay: React.FC<ErrorOverlayProps>;
@@ -60,7 +60,7 @@ function reducer(state, ev) {
60
60
  }
61
61
  }
62
62
  }
63
- const ErrorOverlay = function ErrorOverlay() {
63
+ const ErrorOverlay = function ErrorOverlay({ dismissRuntimeErrors }) {
64
64
  const [state, dispatch] = React.useReducer(reducer, {
65
65
  nextId: 1,
66
66
  buildError: null,
@@ -75,6 +75,6 @@ const ErrorOverlay = function ErrorOverlay() {
75
75
  const hasBuildError = state.buildError != null;
76
76
  const hasRuntimeErrors = Boolean(state.errors.length);
77
77
  const isMounted = hasBuildError || hasRuntimeErrors;
78
- return ((0, jsx_runtime_1.jsx)(React.Fragment, { children: isMounted ? ((0, jsx_runtime_1.jsxs)(ShadowPortal_1.ShadowPortal, { children: [(0, jsx_runtime_1.jsx)(CssReset_1.CssReset, {}), (0, jsx_runtime_1.jsx)(Base_1.Base, {}), (0, jsx_runtime_1.jsx)(ComponentStyles_1.ComponentStyles, {}), hasBuildError ? ((0, jsx_runtime_1.jsx)(BuildError_1.BuildError, { error: state.buildError })) : hasRuntimeErrors ? ((0, jsx_runtime_1.jsx)(RuntimeError_1.RuntimeError, { errors: state.errors })) : undefined] })) : undefined }));
78
+ return ((0, jsx_runtime_1.jsx)(React.Fragment, { children: isMounted ? ((0, jsx_runtime_1.jsxs)(ShadowPortal_1.ShadowPortal, { children: [(0, jsx_runtime_1.jsx)(CssReset_1.CssReset, {}), (0, jsx_runtime_1.jsx)(Base_1.Base, {}), (0, jsx_runtime_1.jsx)(ComponentStyles_1.ComponentStyles, {}), hasBuildError ? ((0, jsx_runtime_1.jsx)(BuildError_1.BuildError, { error: state.buildError })) : hasRuntimeErrors ? ((0, jsx_runtime_1.jsx)(RuntimeError_1.RuntimeError, { errors: state.errors, close: dismissRuntimeErrors })) : undefined] })) : undefined }));
79
79
  };
80
80
  exports.ErrorOverlay = ErrorOverlay;
@@ -6,6 +6,7 @@ export declare type SupportedErrorEvent = {
6
6
  };
7
7
  export declare type RuntimeErrorProps = {
8
8
  errors: SupportedErrorEvent[];
9
+ close: () => void;
9
10
  };
10
11
  export declare const RuntimeError: React.FC<RuntimeErrorProps>;
11
12
  export declare const styles: string;
@@ -48,7 +48,7 @@ function getErrorSignature(ev) {
48
48
  }
49
49
  return '';
50
50
  }
51
- const RuntimeError = function RuntimeError({ errors }) {
51
+ const RuntimeError = function RuntimeError({ errors, close }) {
52
52
  const [lookups, setLookups] = React.useState({});
53
53
  const [readyErrors, nextError] = React.useMemo(() => {
54
54
  let ready = [];
@@ -107,6 +107,7 @@ const RuntimeError = function RuntimeError({ errors }) {
107
107
  const minimize = React.useCallback((e) => {
108
108
  e === null || e === void 0 ? void 0 : e.preventDefault();
109
109
  setDisplayState('minimized');
110
+ close();
110
111
  }, []);
111
112
  const hide = React.useCallback((e) => {
112
113
  e === null || e === void 0 ? void 0 : e.preventDefault();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/error-overlay",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "main": "umd/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "files": [
@@ -23,8 +23,8 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@babel/code-frame": "7.14.5",
26
- "@shuvi/shared": "1.0.26",
27
- "@shuvi/toolpack": "1.0.26",
26
+ "@shuvi/shared": "1.0.28",
27
+ "@shuvi/toolpack": "1.0.28",
28
28
  "anser": "1.4.9",
29
29
  "data-uri-to-buffer": "3.0.1",
30
30
  "html-entities": "2.3.2",