From 74bfa5e1a01df91ae6227ebb03b1aea7de3062a5 Mon Sep 17 00:00:00 2001 From: cmanu Date: Thu, 30 Jul 2026 19:38:47 -0700 Subject: [PATCH] fix(charts): Move chart register --- packages/kilo-ui/src/components/chart.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/kilo-ui/src/components/chart.tsx b/packages/kilo-ui/src/components/chart.tsx index e17195235d7..99892624fe5 100644 --- a/packages/kilo-ui/src/components/chart.tsx +++ b/packages/kilo-ui/src/components/chart.tsx @@ -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 (