Skip to content

Load only the chart types a page draws - #684

Merged
byronwall merged 2 commits into
mainfrom
claude/lean-chart-imports
Nov 20, 2026
Merged

byronwall merged 2 commits into
mainfrom
claude/lean-chart-imports

Conversation

@byronwall

@byronwall byronwall commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

A page that uses explorEDA's standalone charts now downloads only the chart types it draws. exploreda/chart loads each type's code the first time a chart of that type draws. The host writes no setup: the same import { Chart } from "exploreda/chart" now loads less than half the JavaScript up front. For hosts that want no request before the first draw, the new exploreda/chart-core registers chosen types up front.

What you'll see

  • exploreda/chart, the default.
    • No code changes for the host.
    • Each chart type is its own chunk, fetched when a chart of that type first draws. The chart holds its box meanwhile, so nothing moves.
    • Two things load every type, because they can name any type: a settings panel or settings button once it opens, and a Dashboard text config.
  • exploreda/chart-core, for up-front registration.
    • Register the types you draw:
      import { Chart, registerCharts } from "exploreda/chart-core";
      import { barChartDefinition } from "exploreda/charts/bar";
      registerCharts(barChartDefinition);
    • registerCharts checks each definition against its own settings type.
    • An unregistered type shows the two lines to add, in a code block, in its place.
  • All 27 types have an exploreda/charts/<type> import. Nine were missing.
  • Docs. The Standalone charts page has a Load only the charts you use section, with measured sizes and a table of all 27 imports. The README matches.

Proof

pnpm build && pnpm sizes in examples/standalone-charts counts each page's entry chunk plus its static imports. React is included in both counts:

Page Entry Up front, before Up front, now
index.html: 34 charts over all 27 types, settings, a text config exploreda/chart 2,987 KB 1,283 KB
lean.html: a bar chart and a scatter plot exploreda/chart-core — 1,425 KB

On index.html, the rest (2,756 KB) loads after first paint. A check of the production build at 1280 px found all 27 type cards drawn, no chart still loading, no alerts, and no console errors. The settings panel's Chart Type list offered all 27 types.

The lean example page
lean.html: two registered types draw. The third card asks for a line chart that was never registered, and names the import to add.

The chart imports table
The docs table of each chart type, its import path, and its definition name.

pnpm --filter exploreda exec vitest run src/chart
 Tests  102 passed (102)
pnpm check
 PNPM_EXIT=0

Tests:

  • loading.test.tsx, in a fresh module graph with nothing registered:
    • A bar chart first shows a 200 px placeholder, then draws.
    • After that draw, bar is registered and map is not.
    • A text config loads every type.
    • An unknown type reads "nonsense" isn't a chart type.
  • core.test.tsx: the exact import hint, drawing after registerCharts, and that every CHART_IMPORTS entry exists in entries.json and really exports its definition.

Limits

  • The first chart of each type waits for one chunk request. chart-core avoids that wait.
  • Both entries still carry the Dashboard text compiler, because string configs need it. Its two largest files are 65 KB minified in an esbuild measure.

🤖 Generated with Claude Code

byronwall and others added 2 commits November 20, 2026 00:28
exploreda/chart-core exports Chart, ChartSettings, and registerCharts
with no chart type registered; exploreda/chart is that entry plus every
type. All 27 types now have an exploreda/charts/<type> entry; nine were
missing. CHART_IMPORTS maps each type to its entry and export, and a test
checks it against entries.json and the real exports. A chart whose type
isn't registered shows the two lines to add.

In the example app, a page with a bar chart and a scatter plot loads
1,422 KB up front through chart-core against 2,987 KB through chart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
exploreda/chart no longer registers every type when it loads. Each type's
definition is its own chunk, loaded the first time a chart of that type
draws, while the chart holds its box. A settings panel, once open, and a
Dashboard text config load every type, since they can name any.
chart-core keeps explicit, up-front registration.

The example app's first page, 34 charts over all 27 types, now loads
1,283 KB up front, against 2,987 KB before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@byronwall byronwall changed the title Add exploreda/chart-core for lean chart imports Load only the chart types a page draws Nov 20, 2026
@byronwall
byronwall merged commit c0382b8 into main Nov 20, 2026
6 checks passed
@byronwall
byronwall deleted the claude/lean-chart-imports branch November 20, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant