Skip to content

perf(web): cut the shipped JS bundle by 43% - #2391

Merged
DeliciousBuding merged 2 commits into
masterfrom
perf/bundle-trim
Oct 19, 2026
Merged

DeliciousBuding merged 2 commits into
masterfrom
perf/bundle-trim

Conversation

@DeliciousBuding

Copy link
Copy Markdown
Collaborator

Result

Built web output, measured from source-mapped chunks:

before after delta
lazy markdown chunk 1736 KB 217 KB -1519 KB
entry chunk 1723 KB 1401 KB -322 KB
total JS 4845 KB 2765 KB -2080 KB (-43%)

Why

1. react-syntax-highlighter was pulled from its package barrel. The barrel also re-exports the highlight.js build, so the lazy code-block chunk carried 1339 KB of highlight.js it never used, plus 959 KB of refractor from the non-light entry. oneDark came from styles/prism (222 KB, ~200 theme files). CodeBlock now imports dist/esm/prism-light and dist/esm/styles/prism/one-dark directly; prismRegistry already registers exactly the 14 grammars we render.

2. RuntimeIcon imported each provider's index module to reach .Color. Each index re-exports Mono/Text/Avatar/Combine, so 25 providers shipped 189 icon files (664 KB of SVG) into the entry chunk. It now imports es/<Provider>/components/Color.js - the same component that was rendered before. OpenAI/Anthropic/Moonshot have no colour mark and already fell back to the local glyph, so their imports are gone.

Behaviour is unchanged. The only changed assertion is the OpenAI provider case, which previously asserted the mocked .Color (a shape that does not exist in production) and now asserts the real fallback glyph.

Verification

  • tsc shared / workbench / web / desktop: clean.
  • Vitest: shared 151 files / 2758, workbench 163 / 1605, web 33 / 275, desktop 365 / 4881 - all pass.
  • Web production build succeeds; chunk sizes above come from that build.
  • visual:qa:shell 4 shots and visual:qa:chat 16 shots: overflow=false; rendered UI unchanged.

Not done (deliberately)

xlsx (488 KB) and mammoth (397 KB) are already dynamic imports behind preview actions. Splitting the remaining 1401 KB entry chunk by route needs a lazy-route change in WorkbenchRoutes - separate and riskier.

DeliciousBuding and others added 2 commits October 20, 2026 02:18
Measured from the built chunks (source-mapped, grouped by package):

- react-syntax-highlighter was imported from the package barrel, which also re-exports the highlight.js build (1.3 MB), and oneDark came from the 222 KB prism styles barrel. Both now use deep entries: the lazy markdown chunk drops 1736 KB -> 217 KB.
- RuntimeIcon imported each provider's index module to reach its .Color variant; the index also re-exports Mono/Text/Avatar/Combine, so 25 providers shipped 664 KB of SVG. Importing the Color variant directly cuts the main chunk 1723 KB -> 1401 KB. Providers with no colour mark already rendered the fallback glyph, so the three unused index imports are gone.

Co-authored-by: Codex <codex@delicious233.com>
Desktop's tsconfig sets types: [], so @types packages only load when a bare import resolves to them. The deep entries replaced that bare import, which dropped the ambient module declarations and broke typecheck for both CodeBlock and prismRegistry. A type-only import restores them without pulling any runtime code (bundle sizes unchanged).

Co-authored-by: Codex <codex@delicious233.com>
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: TokenDanceLab/AgentHub/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b6c6f9f9-0dd9-45bf-b258-309f461a2190

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@DeliciousBuding
DeliciousBuding merged commit 6ea1421 into master Oct 19, 2026
34 checks passed
@DeliciousBuding
DeliciousBuding deleted the perf/bundle-trim branch October 19, 2026 18:34
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