{"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,SAASC,qBAAqBC,IAAiB;IAC7C,MAAMC,SAAiC,CAAC;IACxC,IAAK,IAAIC,IAAI,GAAGA,IAAIF,KAAKG,UAAU,CAACC,MAAM,EAAEF,IAAK;QAC/C,MAAMG,OAAOL,KAAKG,UAAU,CAACD,EAAE;QAC/BD,MAAM,CAACI,KAAKC,IAAI,CAAC,GAAGD,KAAKE,KAAK;IAChC;IACA,OAAON;AACT;AAEO,MAAMH,gCAAgCU,gBAAS;IAQpDC,YAAYC,KAAyB,CAAE;QACrC,KAAK,CAACA;QACN,IAAI,CAACC,KAAK,GAAG;YAAEC,UAAU;QAAM;QAC/B,IAAI,CAACC,QAAQ,GAAG;QAChB,IAAI,CAACC,cAAc,GAAG,CAAC;QACvB,IAAI,CAACC,OAAO,iBAAGC,IAAAA,gBAAS;IAC1B;IAEA,OAAOC,yBAAyBC,CAAU,EAAsB;QAC9D,OAAO;YAAEN,UAAU;QAAK;IAC1B;IAEAO,oBAAoB;QAClB,MAAMC,WAAW,IAAI,CAACL,OAAO,CAACM,OAAO;QACrC,IAAI,IAAI,CAACV,KAAK,CAACC,QAAQ,IAAIQ,UAAU;YACnC,yDAAyD;YACzDE,OAAOC,OAAO,CAAC,IAAI,CAACT,cAAc,EAAEU,OAAO,CAAC,CAAC,CAACC,KAAKlB,MAAM;gBACvDa,SAASM,YAAY,CAACD,KAAKlB;YAC7B;QACF;IACF;IAEAoB,SAAS;QACP,MAAM,EAAEf,QAAQ,EAAE,GAAG,IAAI,CAACD,KAAK;QAC/B,kDAAkD;QAClD,IAAI,OAAOiB,WAAW,eAAe,CAAC,IAAI,CAACf,QAAQ,EA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