SSR and lifecycle

What the server renders and who owns browser resources.

Server-rendered SVG

renderChartSvg generates SVG from data and options without accessing the DOM. For WordCloud, supply real text metrics through the measurement port.

render-chart.ts
import { renderChartSvg, type ChartData, type ChartOptions } from '@neural-charts/web';

export function renderChart(data: ChartData, options: ChartOptions, instanceId: string): string {
  const result = renderChartSvg(data, options, { instanceId, composition: 'chart' });
  if (result.status === 'invalid') throw new Error(result.diagnostic.message);
  return result.value;
}

Mounting in the browser

Call createChart in the browser once the container is available. If you show static SVG while the page loads, remove it when the interactive chart is ready.

Destruction

Call chart.destroy() when removing the view to release the SVG, listeners, ResizeObserver and pending work.

instanceId

Keep it stable and unique within the document. Changing it identifies a new instance. Avoid random IDs during SSR or data reconstruction.

Identity and lifecycle
SituationWhat to do
Two charts on a pageUse two different, stable instanceIds.
Server renderingRetain the same ID; avoid Math.random and Date.now.
Remove a viewCall chart.destroy().