Recipe-app main
This commit is contained in:
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import { Component, type ReactNode } from 'react';
|
||||
interface ErrorBoundaryProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
interface ErrorBoundaryState {
|
||||
hasError: boolean;
|
||||
}
|
||||
export declare class GracefulDegradeBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
||||
private rootHtml;
|
||||
private htmlAttributes;
|
||||
private htmlRef;
|
||||
constructor(props: ErrorBoundaryProps);
|
||||
static getDerivedStateFromError(_: unknown): ErrorBoundaryState;
|
||||
componentDidMount(): void;
|
||||
render(): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
||||
}
|
||||
export default GracefulDegradeBoundary;
|
||||
Generated
Vendored
+86
@@ -0,0 +1,86 @@
|
||||
'use client';
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
GracefulDegradeBoundary: null,
|
||||
default: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
GracefulDegradeBoundary: function() {
|
||||
return GracefulDegradeBoundary;
|
||||
},
|
||||
default: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
const _jsxruntime = require("react/jsx-runtime");
|
||||
const _react = require("react");
|
||||
function getDomNodeAttributes(node) {
|
||||
const result = {};
|
||||
for(let i = 0; i < node.attributes.length; i++){
|
||||
const attr = node.attributes[i];
|
||||
result[attr.name] = attr.value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
class GracefulDegradeBoundary extends _react.Component {
|
||||
constructor(props){
|
||||
super(props);
|
||||
this.state = {
|
||||
hasError: false
|
||||
};
|
||||
this.rootHtml = '';
|
||||
this.htmlAttributes = {};
|
||||
this.htmlRef = /*#__PURE__*/ (0, _react.createRef)();
|
||||
}
|
||||
static getDerivedStateFromError(_) {
|
||||
return {
|
||||
hasError: true
|
||||
};
|
||||
}
|
||||
componentDidMount() {
|
||||
const htmlNode = this.htmlRef.current;
|
||||
if (this.state.hasError && htmlNode) {
|
||||
// Reapply the cached HTML attributes to the root element
|
||||
Object.entries(this.htmlAttributes).forEach(([key, value])=>{
|
||||
htmlNode.setAttribute(key, value);
|
||||
});
|
||||
}
|
||||
}
|
||||
render() {
|
||||
const { hasError } = this.state;
|
||||
// Cache the root HTML content on the first render
|
||||
if (typeof window !== 'undefined' && !this.rootHtml) {
|
||||
this.rootHtml = document.documentElement.innerHTML;
|
||||
this.htmlAttributes = getDomNodeAttributes(document.documentElement);
|
||||
}
|
||||
if (hasError) {
|
||||
// Render the current HTML content without hydration
|
||||
return /*#__PURE__*/ (0, _jsxruntime.jsx)("html", {
|
||||
ref: this.htmlRef,
|
||||
suppressHydrationWarning: true,
|
||||
dangerouslySetInnerHTML: {
|
||||
__html: this.rootHtml
|
||||
}
|
||||
});
|
||||
}
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
const _default = GracefulDegradeBoundary;
|
||||
|
||||
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=graceful-degrade-boundary.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/client/components/errors/graceful-degrade-boundary.tsx"],"sourcesContent":["'use client'\n\nimport { Component, createRef, type ReactNode } from 'react'\n\ninterface ErrorBoundaryProps {\n children: ReactNode\n}\n\ninterface ErrorBoundaryState {\n hasError: boolean\n}\n\nfunction getDomNodeAttributes(node: HTMLElement): Record<string, string> {\n const result: Record<string, string> = {}\n for (let i = 0; i < node.attributes.length; i++) {\n const attr = node.attributes[i]\n result[attr.name] = attr.value\n }\n return result\n}\n\nexport class GracefulDegradeBoundary extends Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n private rootHtml: string\n private htmlAttributes: Record<string, string>\n private htmlRef: React.RefObject<HTMLHtmlElement | null>\n\n constructor(props: ErrorBoundaryProps) {\n super(props)\n this.state = { hasError: false }\n this.rootHtml = ''\n this.htmlAttributes = {}\n this.htmlRef = createRef<HTMLHtmlElement>()\n }\n\n static getDerivedStateFromError(_: unknown): ErrorBoundaryState {\n return { hasError: true }\n }\n\n componentDidMount() {\n const htmlNode = this.htmlRef.current\n if (this.state.hasError && htmlNode) {\n // Reapply the cached HTML attributes to the root element\n Object.entries(this.htmlAttributes).forEach(([key, value]) => {\n htmlNode.setAttribute(key, value)\n })\n }\n }\n\n render() {\n const { hasError } = this.state\n // Cache the root HTML content on the first render\n if (typeof window !== 'undefined' && !this.rootHtml) {\n this.rootHtml = document.documentElement.innerHTML\n this.htmlAttributes = getDomNodeAttributes(document.documentElement)\n }\n\n if (hasError) {\n // Render the current HTML content without hydration\n return (\n <html\n ref={this.htmlRef}\n suppressHydrationWarning\n dangerouslySetInnerHTML={{\n __html: this.rootHtml,\n }}\n />\n )\n }\n\n return this.props.children\n }\n}\n\nexport default GracefulDegradeBoundary\n"],"names":["GracefulDegradeBoundary","getDomNodeAttributes","node","result","i","attributes","length","attr","name","value","Component","constructor","props","state","hasError","rootHtml","htmlAttributes","htmlRef","createRef","getDerivedStateFromError","_","componentDidMount","htmlNode","current","Object","entries","forEach","key","setAttribute","render","window","document","documentElement","innerHTML","html","ref","suppressHydrationWarning","dangerouslySetInnerHTML","__html","children"],"mappings":"AAAA;;;;;;;;;;;;;;;;IAqBaA,uBAAuB;eAAvBA;;IAuDb,OAAsC;eAAtC;;;;uBA1EqD;AAUrD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wB;gBACxBC,yBAAyB;oBACvBC,QAAQ,IAAI,CAACvB,QAAQ;gBACvB;;QAGN;QAEA,OAAO,IAAI,CAACH,KAAK,CAAC2B,QAAQ;IAC5B;AACF;MAEA,WAAevC","ignoreList":[0]}
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import React, { type JSX } from 'react';
|
||||
import { type ErrorBoundaryProps } from '../error-boundary';
|
||||
export default function RootErrorBoundary({ children, errorComponent, errorStyles, errorScripts, }: ErrorBoundaryProps & {
|
||||
children: React.ReactNode;
|
||||
}): JSX.Element;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
'use client';
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return RootErrorBoundary;
|
||||
}
|
||||
});
|
||||
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
||||
const _jsxruntime = require("react/jsx-runtime");
|
||||
const _react = /*#__PURE__*/ _interop_require_default._(require("react"));
|
||||
const _gracefuldegradeboundary = /*#__PURE__*/ _interop_require_default._(require("./graceful-degrade-boundary"));
|
||||
const _errorboundary = require("../error-boundary");
|
||||
const _isbot = require("../../../shared/lib/router/utils/is-bot");
|
||||
const isBotUserAgent = typeof window !== 'undefined' && (0, _isbot.isBot)(window.navigator.userAgent);
|
||||
function RootErrorBoundary({ children, errorComponent, errorStyles, errorScripts }) {
|
||||
if (isBotUserAgent) {
|
||||
// Preserve existing DOM/HTML for bots to avoid replacing content with an error UI
|
||||
// and to keep the original SSR output intact.
|
||||
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_gracefuldegradeboundary.default, {
|
||||
children: children
|
||||
});
|
||||
}
|
||||
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_errorboundary.ErrorBoundary, {
|
||||
errorComponent: errorComponent,
|
||||
errorStyles: errorStyles,
|
||||
errorScripts: errorScripts,
|
||||
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=root-error-boundary.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/client/components/errors/root-error-boundary.tsx"],"sourcesContent":["'use client'\n\nimport React, { type JSX } from 'react'\nimport GracefulDegradeBoundary from './graceful-degrade-boundary'\nimport { ErrorBoundary, type ErrorBoundaryProps } from '../error-boundary'\nimport { isBot } from '../../../shared/lib/router/utils/is-bot'\n\nconst isBotUserAgent =\n typeof window !== 'undefined' && isBot(window.navigator.userAgent)\n\nexport default function RootErrorBoundary({\n children,\n errorComponent,\n errorStyles,\n errorScripts,\n}: ErrorBoundaryProps & { children: React.ReactNode }): JSX.Element {\n if (isBotUserAgent) {\n // Preserve existing DOM/HTML for bots to avoid replacing content with an error UI\n // and to keep the original SSR output intact.\n return <GracefulDegradeBoundary>{children}</GracefulDegradeBoundary>\n }\n\n return (\n <ErrorBoundary\n errorComponent={errorComponent}\n errorStyles={errorStyles}\n errorScripts={errorScripts}\n >\n {children}\n </ErrorBoundary>\n )\n}\n"],"names":["RootErrorBoundary","isBotUserAgent","window","isBot","navigator","userAgent","children","errorComponent","errorStyles","errorScripts","GracefulDegradeBoundary","ErrorBoundary"],"mappings":"AAAA;;;;;+BAUA;;;eAAwBA;;;;;gEARQ;kFACI;+BACmB;uBACjC;AAEtB,MAAMC,iBACJ,OAAOC,WAAW,eAAeC,IAAAA,YAAK,EAACD,OAAOE,SAAS,CAACC,SAAS;AAEpD,SAASL,kBAAkB,EACxCM,QAAQ,EACRC,cAAc,EACdC,WAAW,EACXC,YAAY,EACuC;IACnD,IAAIR,gBAAgB;QAClB,kFAAkF;QAClF,8CAA8C;QAC9C,qBAAO,qBAACS,gCAAuB;sBAAEJ;;IACnC;IAEA,qBACE,qBAACK,4BAAa;QACZJ,gBAAgBA;QAChBC,aAAaA;QACbC,cAAcA;kBAEbH;;AAGP","ignoreList":[0]}
|
||||
Reference in New Issue
Block a user