fix(charts): Move chart register

This commit is contained in:
cmanu
2026-07-30 19:38:47 -07:00
parent edc6976b72
commit 74bfa5e1a0
+12 -7
View File
@@ -1,9 +1,12 @@
/** @jsxImportSource solid-js */
import { createEffect, createSignal, onCleanup } from "solid-js"
import { Chart, registerables } from "chart.js"
import { BasicTool } from "./basic-tool"
import type { ToolProps } from "./message-part"
import { busy } from "./tool-utils"
Chart.register(...registerables)
function getThemeColors() {
const style = getComputedStyle(document.documentElement)
const get = (v: string, fallback: string) => style.getPropertyValue(v).trim() || fallback
@@ -77,10 +80,13 @@ export function ChartTool(props: ToolProps) {
}
})
import("chart.js").then(({ Chart, registerables }) => {
if (!el.isConnected) return
Chart.register(...registerables)
const chart = new Chart(el, {
let chart: Chart | undefined
onCleanup(() => chart?.destroy())
if (!el.isConnected) return
try {
chart = new Chart(el, {
type: config.type as any,
data: { ...config.data, datasets } as any,
options: {
@@ -106,10 +112,9 @@ export function ChartTool(props: ToolProps) {
...config.options,
},
})
onCleanup(() => chart.destroy())
}).catch((e: unknown) => {
} catch (e) {
setError(e instanceof Error ? e.message : "Failed to render chart")
})
}
})
return (