fix(sector-rotation): 切换分钟桶/资金流后图表永久空白
数据键切换 (1/5/15 分钟桶, 资金流列) 会经过 loading 分支把图表容器 卸载再重挂, 组件本身不卸载: useEChart 的 instRef 仍持有绑在已脱离 DOM 旧节点上的实例, 新数据到达后 setOption 画进离屏节点, 热力图与 切换强度线同时空白。修复: 每次更新前校验实例 dom 与当前 ref 一致, 不一致 (或容器已卸载) 时弃旧实例重建; 浏览器实测 1↔5 分钟往返切换 正常渲染。
This commit is contained in:
1 parent
665c546bb0
commit
f22bf7d3e3
1 file changed
+13
-1
@@ -34,7 +34,19 @@ function useEChart(option: echarts.EChartsOption | null) {
|
||||
}
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
if (!ref.current) return
|
||||
if (!ref.current) {
|
||||
// 容器随 loading 分支被卸载: 旧实例绑在已脱离 DOM 的节点上, 直接释放
|
||||
instRef.current?.dispose()
|
||||
instRef.current = null
|
||||
return
|
||||
}
|
||||
// 数据键切换会走 loading 分支卸载图表容器再重挂, 组件本身不卸载,
|
||||
// 旧实例会绑在脱离 DOM 的旧节点上 — 检测到 dom 不一致必须弃旧重建,
|
||||
// 否则 setOption 画进离屏节点, 图表永久空白 (切 1/5/15 分钟桶复现)
|
||||
if (instRef.current && instRef.current.getDom() !== ref.current) {
|
||||
instRef.current.dispose()
|
||||
instRef.current = null
|
||||
}
|
||||
if (!instRef.current) instRef.current = echarts.init(ref.current, undefined, { renderer: 'canvas' })
|
||||
if (option) {
|
||||
instRef.current.setOption(option, { notMerge: true })
|
||||
|
||||
Reference in new issue
Block a user