Skip to content
Source
Sign inSign up
TanStack/charts

[Size] Export the layer compositor, so SVG-only layers do not bundle the Canvas module #204

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

A mark-level renderer needs a ChartLayerRenderer with compose(defaultRenderer). The only public one is canvasChartRenderer.compose (canvas.ts:185-192). It wraps createLayeredChartRenderer (canvas.ts:439), which is not exported.

That function is not Canvas-specific. It splits scene nodes by node.renderer, mounts one child surface per run, and forwards render, paintFocus and presentation points. Adjacent nodes with the same renderer merge, so separate createSvgChartRenderer() instances give separate SVG layers.

Two costs today:

  • Bundle. Using it for SVG-only layers pulls in the whole Canvas module (22 KB min, about 5.4 KB gzip).
  • Paint. One shared <svg> repaints as a whole while any group animates. With one <svg> per funnel stage (createSvgChartRenderer() instances plus compose: (d) => canvasChartRenderer.compose(d)), main-thread time per hover move fell from a median of 1.79 ms to 0.96 ms (production build, 12 interleaved rounds).

The docs describe the compositor only for Canvas (custom-marks-and-renderers.md:147).

Proposal

Export it from a small module (for example @tanstack/charts/layers), or make it the default when compose is omitted. Document the layer wrapper (pointer-events: none, aria-hidden).

Checked against 57774e14a1a86081eddb3a23523724a40da05640 (v1.1.0).

  1. toomingos(GitHub profile, opens in a new tab) changed the title

  2. Thanks for the detailed report, @toomingos. This shipped in #260 with 1.4.0, so I'm closing it. Custom SVG layers can now use composeChartLayers from @tanstack/charts/layers. Please reopen with a small reproduction if the original SVG-only case still pulls in Canvas painting code.

    AI review notes: The downloaded 1.4.0 npm artifact passed its registry integrity check and exports ./layers with JavaScript and declarations. Its standalone browser closure measures 5.599 kB minified and 2.318 kB gzip on Node 24.18.0. Earlier packed browser checks covered compositor caching, separate host ownership, surface order, updates and SVG adoption in Chromium, Firefox and WebKit. These are focused checks, not a new application-wide performance claim. The renderer guide documents composition and the aria-hidden / pointer-events wrapper contract.

  3. tannerlinsley closed this

Sign in to join this conversation.