Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * @fileoverview ErrorBoundary component for React.
  3. * This component was extracted from the main markdown renderer.
  4. * It catches JavaScript errors anywhere in its child component tree,
  5. * logs those errors, and displays a fallback UI instead of the crashed component tree.
  6. * Primarily used around complex rendering logic like ECharts or SVG within Markdown.
  7. */
  8. import React, { Component } from 'react'
  9. // **Add an ECharts runtime error handler
  10. // Avoid error #7832 (Crash when ECharts accesses undefined objects)
  11. // This can happen when a component attempts to access an undefined object that references an unregistered map, causing the program to crash.
  12. export default class ErrorBoundary extends Component {
  13. constructor(props: any) {
  14. super(props)
  15. this.state = { hasError: false }
  16. }
  17. componentDidCatch(error: any, errorInfo: any) {
  18. this.setState({ hasError: true })
  19. console.error(error, errorInfo)
  20. }
  21. render() {
  22. // eslint-disable-next-line ts/ban-ts-comment
  23. // @ts-expect-error
  24. if (this.state.hasError)
  25. return <div>Oops! An error occurred. This could be due to an ECharts runtime error or invalid SVG content. <br />(see the browser console for more information)</div>
  26. // eslint-disable-next-line ts/ban-ts-comment
  27. // @ts-expect-error
  28. return this.props.children
  29. }
  30. }