Skip to content

Bound the @scalar/api-reference-react bundle footprint with a budget test - #5821

Merged
atomantic merged 2 commits into
mainfrom
claim/issue-5677
Sep 2, 2026
Merged

Bound the @scalar/api-reference-react bundle footprint with a budget test#5821
atomantic merged 2 commits into
mainfrom
claim/issue-5677

Conversation

@atomantic

Copy link
Copy Markdown
Owner

Summary

  • @scalar/api-reference-react powers one developer-facing route (Dev Tools → API Explorer) but is the client's heaviest dependency by a wide margin: 261 of 599 installed packages are reachable only through it, and it contributes 3.24 MB of dist assets against ~13.0 MB of built JS — including a second UI framework (Vue 3 + radix-vue + @headlessui/vue) and the Vercel AI SDK, reached as a hard dependency via @scalar/agent-chat. Nothing measured any of it, so a routine version bump could grow it with no signal.
  • Keeps the dependency — the surveyed alternatives are unmaintained (rapidoc, last published 2024-10) or comparably large — and adds the measurement that was missing.
  • New client/src/pages/ApiExplorer.bundle.test.js: a 4.0 MB budget (~23% headroom over the measured 3.24 MB) over the Scalar-attributable client/dist/assets files. It skips itself when client/dist is absent, so the plain unit-test job stays green; CI runs it as its own step right after npm run build --prefix client, so it sees a fresh build rather than a stale dist/.
  • Non-vacuity guard: the test fails loudly if no ScalarReference-*.js chunk is found, so a Vite chunk-naming change cannot turn the budget into a 0-byte pass.
  • ScalarReference.jsx gains a header note recording the footprint and the fact that agent: { disabled: true } is a runtime toggle — Rollup cannot tree-shake on it, so the agent chat chunk is emitted regardless.
  • docs/DEPS.md: reclassified Tier 1 → Tier 2 with a Detailed Findings entry (measured numbers, why it is kept, what guards it, re-audit trigger).

Out of scope per the issue: no removal or replacement of the dependency, no manualChunks changes, no behaviour change to the API Explorer page.

Test plan

  • cd client && npm test -- src/pages/ApiExplorer.bundle.test.js — 2 passed against a fresh npm run build --prefix client.
  • Failure modes verified by mutation, not assumed:
    • budget lowered to 3.0 MB → fails with the byte breakdown (3394263B over 3145728B).
    • matcher stubbed to match nothing → the non-vacuity assertion fails.
    • client/dist renamed away → suite skips (2 skipped), so the unit-test job stays green.
  • Runs clean both from client/ and with the runner invoked from the repo root.
  • cd client && npm run lint — clean (2428 files).
  • cd server && npm test -- ../scripts/ci-fail-fast.test.js ../scripts/ci-base-sha.test.js ../scripts/ci-test-plan.test.js ../scripts/run-ci-lint.test.js ../scripts/pre-install-entrypoints.test.js — 63 passed; the cancellation step stays the final step of the client job.

Closes #5677

…udget test (#5677)

Scalar powers one developer-facing route (Dev Tools -> API Explorer) but is
the client's heaviest dependency by a wide margin: 261 of 599 installed
packages are reachable only through it, and it contributes 3.24 MB of dist
assets against ~13.0 MB of built JS -- including a second UI framework
(Vue 3) and the Vercel AI SDK, reached as a hard dependency via
@scalar/agent-chat. `agent: { disabled: true }` is a runtime toggle, so
Rollup still emits the agent chat chunk. Nothing measured any of this, so a
routine version bump could grow it without a signal.

Keeps the dependency -- the surveyed alternatives are unmaintained
(rapidoc, last published 2024-10) or comparably large -- and adds the
measurement that was missing: a 4.0 MB budget over the Scalar-attributable
dist assets, checked in CI right after the client build so it sees a fresh
build rather than a stale dist/. The test skips itself when client/dist is
absent, and a companion assertion fails if no ScalarReference-*.js chunk is
found, so a Vite chunk-naming change cannot turn the budget into a 0-byte
pass. Reclassifies the DEPS.md row from Tier 1 to Tier 2 with the measured
numbers and a re-audit trigger.
…k splits (#5677)

Local review flagged two ways the budget could go quiet instead of failing:
resolving dist/assets from cwd alone skipped the whole suite when a runner is
pointed at the client project from the repo root, and matching Vue chunks only
after a dot would miss a vendor chunk if Rollup ever splits the Vue runtime or
radix-vue out on its own. Try both dist paths, and match vue- at a name
boundary.
@atomantic
atomantic merged commit c7ac577 into main Sep 2, 2026
7 checks passed
@atomantic
atomantic deleted the claim/issue-5677 branch September 2, 2026 06:56
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.

Reclassify @scalar/api-reference-react and guard its bundle footprint

1 participant