Problem
Upgrading @copilotkit/react-core + @copilotkit/react-ui from v1.10.x to v1.54.x causes a +21.95 MB bundle size increase due to heavy transitive dependencies pulled in through @copilotkitnext/react.
This is a follow-up to #3225, which was closed after PR #3310 fixed the @copilotkit/runtime leak from runtime-client-gql. However, a separate and larger bundle size problem remains: the @copilotkitnext/react barrel file.
Root Cause
@copilotkitnext/react/dist/index.mjs statically imports all components at the top level:
import CopilotChat from "./components/chat/CopilotChat.mjs";
import CopilotChatAssistantMessage from "./components/chat/CopilotChatAssistantMessage.mjs";
// ... every component
The chat components import heavy dependencies:
CopilotChatAssistantMessage.mjs → streamdown → mermaid (~3 MB minified), shiki (~1 MB)
- Multiple components →
lucide-react (~530 KB minified)
streamdown → katex, cytoscape, langium
Since @copilotkitnext/react has:
- No
sideEffects field in package.json — bundlers assume all imports have side effects
- No subpath exports — consumers can't import just hooks without triggering the barrel
- Barrel file with static imports — even unused components are pulled into the module graph
Any consumer importing from @copilotkit/react-core (which re-exports hooks from @copilotkitnext/react) gets the entire dependency tree.
Impact
| Metric |
v1.10.6 |
v1.54.1 |
Delta |
| Top-level packages in node_modules |
178 |
321 |
+143 (+80%) |
| node_modules disk size |
111 MB |
416 MB |
+305 MB |
| Bundle size (Codecov) |
baseline |
+21.95 MB |
+12.16% |
The build also OOMs with 8 GB heap due to the bundler trying to process mermaid's massive module graph.
Proposed Fixes
Immediate: Add sideEffects declaration (PR #3652)
Adding "sideEffects": ["**/*.css"] to @copilotkitnext/react's package.json allows bundlers to tree-shake unused components. This completely eliminates mermaid/shiki/streamdown for hook-only consumers.
Follow-up suggestions
- Subpath exports — e.g.,
@copilotkitnext/react/hooks so consumers can bypass the barrel entirely
- Make heavy renderers opt-in — mermaid, shiki, and katex could be peer/optional dependencies or loaded via a plugin pattern, so consumers who don't need diagram/code rendering don't pay the cost
- Add
sideEffects: false to streamdown — this package also lacks the field, preventing tree-shaking even when the consumer package is properly configured
Reproduction
mkdir test && cd test
echo '{"dependencies":{"@copilotkit/react-core":"1.54.1","@copilotkit/react-ui":"1.54.1"}}' > package.json
npm install
du -sh node_modules # 416 MB
Environment
- Bundler: rspack 1.3.x (also affects webpack 5)
- CopilotKit version: 1.54.1
- Previous working version: 1.10.6
Problem
Upgrading
@copilotkit/react-core+@copilotkit/react-uifrom v1.10.x to v1.54.x causes a +21.95 MB bundle size increase due to heavy transitive dependencies pulled in through@copilotkitnext/react.This is a follow-up to #3225, which was closed after PR #3310 fixed the
@copilotkit/runtimeleak fromruntime-client-gql. However, a separate and larger bundle size problem remains: the@copilotkitnext/reactbarrel file.Root Cause
@copilotkitnext/react/dist/index.mjsstatically imports all components at the top level:The chat components import heavy dependencies:
CopilotChatAssistantMessage.mjs→streamdown→mermaid(~3 MB minified),shiki(~1 MB)lucide-react(~530 KB minified)streamdown→katex,cytoscape,langiumSince
@copilotkitnext/reacthas:sideEffectsfield in package.json — bundlers assume all imports have side effectsAny consumer importing from
@copilotkit/react-core(which re-exports hooks from@copilotkitnext/react) gets the entire dependency tree.Impact
The build also OOMs with 8 GB heap due to the bundler trying to process mermaid's massive module graph.
Proposed Fixes
Immediate: Add
sideEffectsdeclaration (PR #3652)Adding
"sideEffects": ["**/*.css"]to@copilotkitnext/react's package.json allows bundlers to tree-shake unused components. This completely eliminates mermaid/shiki/streamdown for hook-only consumers.Follow-up suggestions
@copilotkitnext/react/hooksso consumers can bypass the barrel entirelysideEffects: falsetostreamdown— this package also lacks the field, preventing tree-shaking even when the consumer package is properly configuredReproduction
Environment