You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue #87 asks how to use CUSTOM_SYMBOL_FN in Next.js. The existing Custom Symbols guide is thorough for browser environments, but it uses document.createElementNS(...) in all its examples.
In Next.js (and any other SSR framework), this call runs during server-side rendering where document is not defined, causing a ReferenceError: document is not defined crash.
What is missing from the docs
An explicit SSR warning — note that CUSTOM_SYMBOL_FN (and the whole chart rendering) must run client-side only.
A Next.js-specific pattern — show how to guard the chart initialisation so it only runs in the browser:
Using typeof window !== 'undefined' guards
Using a useEffect hook (the correct React pattern for DOM/SVG manipulation)
Using Next.js dynamic(() => import('./MyChart'), { ssr: false }) to load the chart component without SSR
A note in the Frameworks guide — the existing guides/frameworks/ directory has pages for React, Angular, and Vue; these should each mention that Chart must be instantiated inside a lifecycle hook / after hydration, and that CUSTOM_SYMBOL_FN callbacks follow the same rule.
Example that should be added
// In Next.js — correct pattern (runs only in the browser)import{useEffect,useRef}from'react'import{Chart}from'@astrodraw/astrochart'exportdefaultfunctionMyChart({ data }){constref=useRef(null)useEffect(()=>{if(!ref.current)returnconstchart=newChart(ref.current.id,600,600,{CUSTOM_SYMBOL_FN: (name,x,y)=>{// document is safely available here — we are in the browserconstel=document.createElementNS('http://www.w3.org/2000/svg','circle')el.setAttribute('cx',String(x))el.setAttribute('cy',String(y))el.setAttribute('r','8')el.setAttribute('fill','#FFD700')returnel}})chart.radix(data)},[data])return<divid="my-chart"ref={ref}/>}
Context
Issue #87 asks how to use
CUSTOM_SYMBOL_FNin Next.js. The existing Custom Symbols guide is thorough for browser environments, but it usesdocument.createElementNS(...)in all its examples.In Next.js (and any other SSR framework), this call runs during server-side rendering where
documentis not defined, causing aReferenceError: document is not definedcrash.What is missing from the docs
CUSTOM_SYMBOL_FN(and the whole chart rendering) must run client-side only.typeof window !== 'undefined'guardsuseEffecthook (the correct React pattern for DOM/SVG manipulation)dynamic(() => import('./MyChart'), { ssr: false })to load the chart component without SSRguides/frameworks/directory has pages for React, Angular, and Vue; these should each mention thatChartmust be instantiated inside a lifecycle hook / after hydration, and thatCUSTOM_SYMBOL_FNcallbacks follow the same rule.Example that should be added
Relevant links
website/src/content/docs/guides/custom-symbols.mdwebsite/src/content/docs/guides/frameworks/