UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

35 lines 1.31 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import React from 'react'; import { IntlProvider } from 'react-intl-next'; export const REACT_INTL_ERROR_MESSAGE = '<IntlProvider> needs to exist in the component ancestry'; const isMissingIntlProviderInAncestryError = err => { var _err$toString; return err === null || err === void 0 ? void 0 : (_err$toString = err.toString()) === null || _err$toString === void 0 ? void 0 : _err$toString.includes('<IntlProvider> needs to exist in the component ancestry'); }; export class IntlErrorBoundary extends React.Component { constructor(...args) { super(...args); _defineProperty(this, "state", { missingIntlProviderInAncestry: false }); } componentDidCatch(error, errorInfo) { // if missing IntlProvider in ancestry, we setup a fallback IntlProvider ourselves if (isMissingIntlProviderInAncestryError(error)) { this.setState({ missingIntlProviderInAncestry: true }); } else { // else we re-propagate the non-react-intl-next error throw error; } } render() { if (this.state.missingIntlProviderInAncestry) { return /*#__PURE__*/React.createElement(IntlProvider, { locale: "en" }, this.props.children); } return this.props.children; } }