fix(charts): bot suggestion applied for cleanup

This commit is contained in:
cmanu
2026-07-31 07:32:39 -07:00
parent c94d49ce2d
commit 2d7b71f118
+8 -6
View File
@@ -59,7 +59,13 @@ export function ChartTool(props: ToolProps) {
return
}
rendered = true
let chart: Chart | undefined
onCleanup(() => {
chart?.destroy()
rendered = false
})
if (!el.isConnected) return
const colors = getThemeColors()
const isPolar = config.type === "pie" || config.type === "doughnut" || config.type === "polarArea"
@@ -81,11 +87,6 @@ export function ChartTool(props: ToolProps) {
}
})
let chart: Chart | undefined
onCleanup(() => chart?.destroy())
if (!el.isConnected) return
try {
chart = new Chart(el, {
type: config.type as any,
@@ -113,6 +114,7 @@ export function ChartTool(props: ToolProps) {
...config.options,
},
})
rendered = true
} catch (e) {
setError(e instanceof Error ? e.message : "Failed to render chart")
}