Skip to content
Source
Sign inSign up
TanStack/charts

React `Chart`: a way to skip the server SVG and mount after hydration #175

Closedquantizor(GitHub profile, opens in a new tab) opened this issue 1 comment

Version: @tanstack/charts 1.0.0.

In an app with server components and server rendering, I want the server markup for a chart to be only its fixed-size frame, with the chart drawn after mount. The React adapter always prerenders the full SVG; the adapter page says "There is no placeholder-only server mode" (docs/framework/react/adapter.md).

Rendering <Chart> only after a mount flag works, and the client-only path has a test (Chart.test.tsx, "builds and serializes a client-only chart once before parent layout effects"). But the SSR guide says "Do not conditionally replace a chart with a different component only because the code is executing on the server", so it is unclear whether that gate is supported.

Would it be possible to add a prop such as prerender?: boolean (default true)? With false, the server and hydration renders would both produce the outer host with its height or aspectRatio box and an empty surface, so nothing mismatches, and the host would mount in the layout effect as it does for a client-only render. A short documented gate pattern would also settle it.

  1. The documented gate alternative is now included in 1.1.0. The SSR guide shows an application-owned mount gate that keeps the server and first hydration render consistent, with a fixed-size placeholder. We added Strict Mode hydration and teardown coverage. No new prerender prop was needed.

  2. tannerlinsley closed this

Sign in to join this conversation.