Files
gsfdc/demo-dify/dify/web/app/components/base/markdown/error-boundary.tsx
T
wuzilongandCursor 6519682885 chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 13:59:25 +08:00

42 lines
1.4 KiB
TypeScript

/**
* @fileoverview ErrorBoundary component for React.
* This component was extracted from the main markdown renderer.
* It catches JavaScript errors anywhere in its child component tree,
* logs those errors, and displays a fallback UI instead of the crashed component tree.
* Primarily used around complex rendering logic like ECharts or SVG within Markdown.
*/
import * as React from 'react'
import { Component } from 'react'
// **Add an ECharts runtime error handler
// Avoid error #7832 (Crash when ECharts accesses undefined objects)
// This can happen when a component attempts to access an undefined object that references an unregistered map, causing the program to crash.
export default class ErrorBoundary extends Component<
React.PropsWithChildren,
{ hasError: boolean }
> {
constructor(props: React.PropsWithChildren) {
super(props)
this.state = { hasError: false }
}
override componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
this.setState({ hasError: true })
console.error(error, errorInfo)
}
override render() {
if (this.state.hasError) {
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>
)
}
return this.props.children
}
}