134 lines
4.7 KiB
JavaScript
134 lines
4.7 KiB
JavaScript
|
"use client";
|
||
|
|
||
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
0 && (module.exports = {
|
||
|
ErrorBoundaryHandler: null,
|
||
|
GlobalError: null,
|
||
|
default: null,
|
||
|
ErrorBoundary: null
|
||
|
});
|
||
|
function _export(target, all) {
|
||
|
for(var name in all)Object.defineProperty(target, name, {
|
||
|
enumerable: true,
|
||
|
get: all[name]
|
||
|
});
|
||
|
}
|
||
|
_export(exports, {
|
||
|
ErrorBoundaryHandler: function() {
|
||
|
return ErrorBoundaryHandler;
|
||
|
},
|
||
|
GlobalError: function() {
|
||
|
return GlobalError;
|
||
|
},
|
||
|
// Exported so that the import signature in the loaders can be identical to user
|
||
|
// supplied custom global error signatures.
|
||
|
default: function() {
|
||
|
return _default;
|
||
|
},
|
||
|
ErrorBoundary: function() {
|
||
|
return ErrorBoundary;
|
||
|
}
|
||
|
});
|
||
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
||
|
const _react = /*#__PURE__*/ _interop_require_default._(require("react"));
|
||
|
const _navigation = require("./navigation");
|
||
|
const styles = {
|
||
|
error: {
|
||
|
// https://github.com/sindresorhus/modern-normalize/blob/main/modern-normalize.css#L38-L52
|
||
|
fontFamily: 'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"',
|
||
|
height: "100vh",
|
||
|
textAlign: "center",
|
||
|
display: "flex",
|
||
|
flexDirection: "column",
|
||
|
alignItems: "center",
|
||
|
justifyContent: "center"
|
||
|
},
|
||
|
text: {
|
||
|
fontSize: "14px",
|
||
|
fontWeight: 400,
|
||
|
lineHeight: "28px",
|
||
|
margin: "0 8px"
|
||
|
}
|
||
|
};
|
||
|
class ErrorBoundaryHandler extends _react.default.Component {
|
||
|
static getDerivedStateFromError(error) {
|
||
|
return {
|
||
|
error
|
||
|
};
|
||
|
}
|
||
|
static getDerivedStateFromProps(props, state) {
|
||
|
/**
|
||
|
* Handles reset of the error boundary when a navigation happens.
|
||
|
* Ensures the error boundary does not stay enabled when navigating to a new page.
|
||
|
* Approach of setState in render is safe as it checks the previous pathname and then overrides
|
||
|
* it as outlined in https://react.dev/reference/react/useState#storing-information-from-previous-renders
|
||
|
*/ if (props.pathname !== state.previousPathname && state.error) {
|
||
|
return {
|
||
|
error: null,
|
||
|
previousPathname: props.pathname
|
||
|
};
|
||
|
}
|
||
|
return {
|
||
|
error: state.error,
|
||
|
previousPathname: props.pathname
|
||
|
};
|
||
|
}
|
||
|
render() {
|
||
|
if (this.state.error) {
|
||
|
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, this.props.errorStyles, /*#__PURE__*/ _react.default.createElement(this.props.errorComponent, {
|
||
|
error: this.state.error,
|
||
|
reset: this.reset
|
||
|
}));
|
||
|
}
|
||
|
return this.props.children;
|
||
|
}
|
||
|
constructor(props){
|
||
|
super(props);
|
||
|
this.reset = ()=>{
|
||
|
this.setState({
|
||
|
error: null
|
||
|
});
|
||
|
};
|
||
|
this.state = {
|
||
|
error: null,
|
||
|
previousPathname: this.props.pathname
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
function GlobalError(param) {
|
||
|
let { error } = param;
|
||
|
const digest = error == null ? void 0 : error.digest;
|
||
|
return /*#__PURE__*/ _react.default.createElement("html", {
|
||
|
id: "__next_error__"
|
||
|
}, /*#__PURE__*/ _react.default.createElement("head", null), /*#__PURE__*/ _react.default.createElement("body", null, /*#__PURE__*/ _react.default.createElement("div", {
|
||
|
style: styles.error
|
||
|
}, /*#__PURE__*/ _react.default.createElement("div", null, /*#__PURE__*/ _react.default.createElement("h2", {
|
||
|
style: styles.text
|
||
|
}, "Application error: a " + (digest ? "server" : "client") + "-side exception has occurred (see the " + (digest ? "server logs" : "browser console") + " for more information)."), digest ? /*#__PURE__*/ _react.default.createElement("p", {
|
||
|
style: styles.text
|
||
|
}, "Digest: " + digest) : null))));
|
||
|
}
|
||
|
const _default = GlobalError;
|
||
|
function ErrorBoundary(param) {
|
||
|
let { errorComponent, errorStyles, children } = param;
|
||
|
const pathname = (0, _navigation.usePathname)();
|
||
|
if (errorComponent) {
|
||
|
return /*#__PURE__*/ _react.default.createElement(ErrorBoundaryHandler, {
|
||
|
pathname: pathname,
|
||
|
errorComponent: errorComponent,
|
||
|
errorStyles: errorStyles
|
||
|
}, children);
|
||
|
}
|
||
|
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, children);
|
||
|
}
|
||
|
|
||
|
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
||
|
Object.defineProperty(exports.default, '__esModule', { value: true });
|
||
|
Object.assign(exports.default, exports);
|
||
|
module.exports = exports.default;
|
||
|
}
|
||
|
|
||
|
//# sourceMappingURL=error-boundary.js.map
|