126 lines
6.0 KiB
JavaScript
126 lines
6.0 KiB
JavaScript
'use client';
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "HTTPAccessFallbackBoundary", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return HTTPAccessFallbackBoundary;
|
|
}
|
|
});
|
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
const _jsxruntime = require("react/jsx-runtime");
|
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
const _navigationuntracked = require("../navigation-untracked");
|
|
const _httpaccessfallback = require("./http-access-fallback");
|
|
const _warnonce = require("../../../shared/lib/utils/warn-once");
|
|
const _approutercontextsharedruntime = require("../../../shared/lib/app-router-context.shared-runtime");
|
|
class HTTPAccessFallbackErrorBoundary extends _react.default.Component {
|
|
componentDidCatch() {
|
|
if (process.env.NODE_ENV === 'development' && this.props.missingSlots && this.props.missingSlots.size > 0 && // A missing children slot is the typical not-found case, so no need to warn
|
|
!this.props.missingSlots.has('children')) {
|
|
let warningMessage = 'No default component was found for a parallel route rendered on this page. Falling back to nearest NotFound boundary.\n' + 'Learn more: https://nextjs.org/docs/app/building-your-application/routing/parallel-routes#defaultjs\n\n';
|
|
const formattedSlots = Array.from(this.props.missingSlots).sort((a, b)=>a.localeCompare(b)).map((slot)=>"@" + slot).join(', ');
|
|
warningMessage += 'Missing slots: ' + formattedSlots;
|
|
(0, _warnonce.warnOnce)(warningMessage);
|
|
}
|
|
}
|
|
static getDerivedStateFromError(error) {
|
|
if ((0, _httpaccessfallback.isHTTPAccessFallbackError)(error)) {
|
|
const httpStatus = (0, _httpaccessfallback.getAccessFallbackHTTPStatus)(error);
|
|
return {
|
|
triggeredStatus: httpStatus
|
|
};
|
|
}
|
|
// Re-throw if error is not for 404
|
|
throw 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.triggeredStatus) {
|
|
return {
|
|
triggeredStatus: undefined,
|
|
previousPathname: props.pathname
|
|
};
|
|
}
|
|
return {
|
|
triggeredStatus: state.triggeredStatus,
|
|
previousPathname: props.pathname
|
|
};
|
|
}
|
|
render() {
|
|
const { notFound, forbidden, unauthorized, children } = this.props;
|
|
const { triggeredStatus } = this.state;
|
|
const errorComponents = {
|
|
[_httpaccessfallback.HTTPAccessErrorStatus.NOT_FOUND]: notFound,
|
|
[_httpaccessfallback.HTTPAccessErrorStatus.FORBIDDEN]: forbidden,
|
|
[_httpaccessfallback.HTTPAccessErrorStatus.UNAUTHORIZED]: unauthorized
|
|
};
|
|
if (triggeredStatus) {
|
|
const isNotFound = triggeredStatus === _httpaccessfallback.HTTPAccessErrorStatus.NOT_FOUND && notFound;
|
|
const isForbidden = triggeredStatus === _httpaccessfallback.HTTPAccessErrorStatus.FORBIDDEN && forbidden;
|
|
const isUnauthorized = triggeredStatus === _httpaccessfallback.HTTPAccessErrorStatus.UNAUTHORIZED && unauthorized;
|
|
// If there's no matched boundary in this layer, keep throwing the error by rendering the children
|
|
if (!(isNotFound || isForbidden || isUnauthorized)) {
|
|
return children;
|
|
}
|
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
children: [
|
|
/*#__PURE__*/ (0, _jsxruntime.jsx)("meta", {
|
|
name: "robots",
|
|
content: "noindex"
|
|
}),
|
|
process.env.NODE_ENV === 'development' && /*#__PURE__*/ (0, _jsxruntime.jsx)("meta", {
|
|
name: "boundary-next-error",
|
|
content: (0, _httpaccessfallback.getAccessFallbackErrorTypeByStatus)(triggeredStatus)
|
|
}),
|
|
errorComponents[triggeredStatus]
|
|
]
|
|
});
|
|
}
|
|
return children;
|
|
}
|
|
constructor(props){
|
|
super(props);
|
|
this.state = {
|
|
triggeredStatus: undefined,
|
|
previousPathname: props.pathname
|
|
};
|
|
}
|
|
}
|
|
function HTTPAccessFallbackBoundary(param) {
|
|
let { notFound, forbidden, unauthorized, children } = param;
|
|
// When we're rendering the missing params shell, this will return null. This
|
|
// is because we won't be rendering any not found boundaries or error
|
|
// boundaries for the missing params shell. When this runs on the client
|
|
// (where these error can occur), we will get the correct pathname.
|
|
const pathname = (0, _navigationuntracked.useUntrackedPathname)();
|
|
const missingSlots = (0, _react.useContext)(_approutercontextsharedruntime.MissingSlotContext);
|
|
const hasErrorFallback = !!(notFound || forbidden || unauthorized);
|
|
if (hasErrorFallback) {
|
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(HTTPAccessFallbackErrorBoundary, {
|
|
pathname: pathname,
|
|
notFound: notFound,
|
|
forbidden: forbidden,
|
|
unauthorized: unauthorized,
|
|
missingSlots: missingSlots,
|
|
children: children
|
|
});
|
|
}
|
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
|
|
children: 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
|