mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-06-30 14:55:13 +08:00
fix(echarts): Resolve chart flickering and animation loop in Markdown (#20161)
This commit is contained in:
parent
9b1dc1de7a
commit
cbfc32b11f
@ -134,6 +134,24 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any
|
|||||||
const languageShowName = getCorrectCapitalizationLanguageName(language || '')
|
const languageShowName = getCorrectCapitalizationLanguageName(language || '')
|
||||||
const isDarkMode = theme === Theme.dark
|
const isDarkMode = theme === Theme.dark
|
||||||
|
|
||||||
|
const echartsStyle = useMemo(() => ({
|
||||||
|
height: '350px',
|
||||||
|
width: '100%',
|
||||||
|
}), [])
|
||||||
|
|
||||||
|
const echartsOpts = useMemo(() => ({
|
||||||
|
renderer: 'canvas',
|
||||||
|
width: 'auto',
|
||||||
|
}) as any, [])
|
||||||
|
|
||||||
|
const echartsOnEvents = useMemo(() => ({
|
||||||
|
finished: () => {
|
||||||
|
const instance = echartsRef.current?.getEchartsInstance?.()
|
||||||
|
if (instance)
|
||||||
|
instance.resize()
|
||||||
|
},
|
||||||
|
}), [echartsRef]) // echartsRef is stable, so this effectively runs once.
|
||||||
|
|
||||||
// Handle container resize for echarts
|
// Handle container resize for echarts
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (language !== 'echarts' || !echartsRef.current) return
|
if (language !== 'echarts' || !echartsRef.current) return
|
||||||
@ -329,24 +347,11 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any
|
|||||||
<ReactEcharts
|
<ReactEcharts
|
||||||
ref={echartsRef}
|
ref={echartsRef}
|
||||||
option={finalChartOption}
|
option={finalChartOption}
|
||||||
style={{
|
style={echartsStyle}
|
||||||
height: '350px',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
theme={isDarkMode ? 'dark' : undefined}
|
theme={isDarkMode ? 'dark' : undefined}
|
||||||
opts={{
|
opts={echartsOpts}
|
||||||
renderer: 'canvas',
|
|
||||||
width: 'auto',
|
|
||||||
}}
|
|
||||||
notMerge={true}
|
notMerge={true}
|
||||||
onEvents={{
|
onEvents={echartsOnEvents}
|
||||||
// Force resize when chart is finished rendering
|
|
||||||
finished: () => {
|
|
||||||
const instance = echartsRef.current?.getEchartsInstance?.()
|
|
||||||
if (instance)
|
|
||||||
instance.resize()
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</div>
|
</div>
|
||||||
@ -374,15 +379,9 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any
|
|||||||
<ReactEcharts
|
<ReactEcharts
|
||||||
ref={echartsRef}
|
ref={echartsRef}
|
||||||
option={errorOption}
|
option={errorOption}
|
||||||
style={{
|
style={echartsStyle}
|
||||||
height: '350px',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
theme={isDarkMode ? 'dark' : undefined}
|
theme={isDarkMode ? 'dark' : undefined}
|
||||||
opts={{
|
opts={echartsOpts}
|
||||||
renderer: 'canvas',
|
|
||||||
width: 'auto',
|
|
||||||
}}
|
|
||||||
notMerge={true}
|
notMerge={true}
|
||||||
/>
|
/>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
@ -423,7 +422,7 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any
|
|||||||
</SyntaxHighlighter>
|
</SyntaxHighlighter>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}, [children, language, isSVG, finalChartOption, props, theme, match])
|
}, [children, language, isSVG, finalChartOption, props, theme, match, chartState, isDarkMode, echartsStyle, echartsOpts, echartsOnEvents])
|
||||||
|
|
||||||
if (inline || !match)
|
if (inline || !match)
|
||||||
return <code {...props} className={className}>{children}</code>
|
return <code {...props} className={className}>{children}</code>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user