UNPKG

@airplane/views

Version:

A React library for building Airplane views. Views components are optimized in style and functionality to produce internal apps that are easy to build and maintain.

53 lines (52 loc) 1.57 kB
import { jsx } from "react/jsx-runtime"; import { uniqueId } from "lodash-es"; import hash from "object-hash"; import { Component } from "react"; import { getNPMPackageVersion } from "../../getNPMPackageVersion.js"; import { sendViewMessage } from "../../message/sendViewMessage.js"; import { ComponentErrorFallback } from "./ComponentErrorFallback.js"; class ComponentErrorBoundary extends Component { constructor(props) { super(props); this.state = {}; } componentDidMount() { const version = getNPMPackageVersion(); sendViewMessage({ type: "component_mounted", componentName: this.props.componentName, version }); } componentDidCatch(error, errorInfo) { const errorID = uniqueId(); this.setState({ error, errorInfo, errorID }); sendViewMessage({ type: "console", id: errorID, messageType: "error", message: error.message, component: this.props.componentName, hash: hash(error), time: Date.now() }); } render() { if (this.state.error && this.state.errorInfo && this.state.errorID) { if (this.props.fallback) { return this.props.fallback; } return /* @__PURE__ */ jsx(ComponentErrorFallback, { errorID: this.state.errorID, error: this.state.error, errorInfo: this.state.errorInfo, componentName: this.props.componentName, latestRun: this.props.latestRun }); } else { return this.props.children; } } } export { ComponentErrorBoundary }; //# sourceMappingURL=ComponentErrorBoundary.js.map