{"version":3,"file":"HostRenderErrorBoundary.mjs","names":[],"sources":["../../../src/components/HostRenderErrorBoundary.tsx"],"sourcesContent":["import { Component, type ReactNode } from \"react\";\n\nconst HOST_ERROR_DELIVERY_TIMEOUT_MS = 1000;\n\nconst isNoComponentFoundError = (error: unknown): error is Error =>\n  // Couples to the message thrown by @mittwald/remote-dom-react's host renderer.\n  error instanceof Error &&\n  error.message.startsWith(\"No component found for remote element\");\n\ninterface Props {\n  children: ReactNode;\n  onNoComponentError: (error: Error) => Promise<void>;\n}\n\ninterface State {\n  errorToRethrow?: unknown;\n  isHandling: boolean;\n}\n\nexport class HostRenderErrorBoundary extends Component<Props, State> {\n  override state: State = { isHandling: false };\n\n  static getDerivedStateFromError(error: unknown): Partial<State> {\n    if (isNoComponentFoundError(error)) {\n      return { isHandling: true };\n    }\n\n    return { errorToRethrow: error };\n  }\n\n  override componentDidCatch(error: unknown): void {\n    if (!isNoComponentFoundError(error)) {\n      return;\n    }\n\n    const timeout = new Promise<void>((resolve) =>\n      setTimeout(resolve, HOST_ERROR_DELIVERY_TIMEOUT_MS),\n    );\n\n    Promise.race([\n      this.props.onNoComponentError(error).catch(() => undefined),\n      timeout,\n    ]).finally(() => {\n      this.setState({ errorToRethrow: error, isHandling: false });\n    });\n  }\n\n  override render(): ReactNode {\n    if (\"errorToRethrow\" in this.state) {\n      throw this.state.errorToRethrow;\n    }\n\n    if (this.state.isHandling) {\n      return null;\n    }\n\n    return this.props.children;\n  }\n}\n"],"mappings":";;;;AAEA,IAAM,iCAAiC;AAEvC,IAAM,2BAA2B,UAE/B,iBAAiB,SACjB,MAAM,QAAQ,WAAW,uCAAuC;AAYlE,IAAa,0BAAb,cAA6C,UAAwB;CACnE,QAAwB,EAAE,YAAY,MAAM;CAE5C,OAAO,yBAAyB,OAAgC;EAC9D,IAAI,wBAAwB,KAAK,GAC/B,OAAO,EAAE,YAAY,KAAK;EAG5B,OAAO,EAAE,gBAAgB,MAAM;CACjC;CAEA,kBAA2B,OAAsB;EAC/C,IAAI,CAAC,wBAAwB,KAAK,GAChC;EAGF,MAAM,UAAU,IAAI,SAAe,YACjC,WAAW,SAAS,8BAA8B,CACpD;EAEA,QAAQ,KAAK,CACX,KAAK,MAAM,mBAAmB,KAAK,CAAC,CAAC,YAAY,KAAA,CAAS,GAC1D,OACF,CAAC,CAAC,CAAC,cAAc;GACf,KAAK,SAAS;IAAE,gBAAgB;IAAO,YAAY;GAAM,CAAC;EAC5D,CAAC;CACH;CAEA,SAA6B;EAC3B,IAAI,oBAAoB,KAAK,OAC3B,MAAM,KAAK,MAAM;EAGnB,IAAI,KAAK,MAAM,YACb,OAAO;EAGT,OAAO,KAAK,MAAM;CACpB;AACF"}