Repository navigation
Description
Hi, thanks for maintaining styled-components.
Filing this because in our monorepo the 6.4.2 → 6.4.3 bump added enough tsc pressure to start OOMing our dev-server type checker. Feel free to close if you knew about the trade-off and decided it was worthwhile so this is WAI.
We bisected on the same commit and same lockfile, swapping only styled-components between 6.4.2 and 6.4.3, running tsc --extendedDiagnostics --noEmit cold each time (deleted .tsbuildinfo before every run, alternated the order A→B→A→B to rule out caching artifacts):
| Metric | 6.4.2 (run 1) | 6.4.3 (run 1) | 6.4.2 (run 2) | 6.4.3 (run 2) |
|---|---|---|---|---|
| Types | 1,487,074 | 1,892,984 | 1,487,074 | 1,892,984 |
| Instantiations | 33,223,024 | 47,784,078 | 33,223,024 | 47,784,078 |
| Symbols | 3,701,255 | 3,703,629 | 3,701,255 | 3,703,629 |
| Memory used | 3,427 MB | 5,244 MB | 3,555 MB | 5,133 MB |
| Check time | 70.0s | 91.4s | 70.9s | 103.2s |
Structural metrics are bit-identical per-version; memory/time jitter run-to-run as expected. Net effect of the 6.4.2 → 6.4.3 bump:
- +406,282 types (+27%)
- +14,561,054 instantiations (+44%)
- +1.6 GB heap (+45%)
- +22–33s check time (+30–45%)
We used --generateTrace to attribute the growth. It is not spread across the codebase — it is concentrated in a single symbol:
Symbol (from @types/react) |
6.4.2 | 6.4.3 | Delta |
|---|---|---|---|
ComponentPropsWithRef |
4,428 | 252,248 | +247,820 (57×) |
By flag: +258,286 new Conditional types and +146,454 new Intersection types, essentially entirely rooted in @types/react instantiations from styled-components.
Comparing styled-components/dist/types.d.ts between the two versions, the change is the new PolymorphicCallProps alias and the widened AsTarget bound in PolymorphicComponentProps (referenced in your own comment as ~6% more instantiations across call sites):
// 6.4.3 additions
export type PolymorphicComponentProps<R, BaseProps,
AsTarget extends StyledTarget<R> | (BaseProps extends { as?: infer A } ? A : never) | void,
ForwardedAsTarget extends StyledTarget<R> | void,
AsTargetProps extends BaseObject = AsTarget extends KnownTarget ? React.ComponentPropsWithRef<AsTarget> : {},
ForwardedAsTargetProps extends BaseObject = ForwardedAsTarget extends KnownTarget ? React.ComponentPropsWithRef<ForwardedAsTarget> : {},
> = ...
type PolymorphicCallProps<R, BaseProps, AsTarget, ForwardedAsTarget> =
[AsTarget] extends [string | AnyComponent] ? PolymorphicComponentProps<...> & { as: AsTarget }
: [ForwardedAsTarget] extends [void] ? OverrideStyle<...>
: PolymorphicComponentProps<R, BaseProps, void, ForwardedAsTarget> & { forwardedAs: ForwardedAsTarget };Every JSX usage of a styled component now goes through the three-branch conditional, and each branch that lands on the target-props branch re-instantiates React.ComponentPropsWithRef (already a known TS hotspot). The comment on the type acknowledges the tradeoff for
KnownTarget narrowing but the multiplier we see in a real app is much larger than 6%.
Scale of usage on our side: a large SPA, heavy styled(Component) and styled.div usage across ~2000 components.
Repro: any large codebase with heavy styled() usage; alternate installs of 6.4.2 and 6.4.3 with .tsbuildinfo deleted each time, run tsc --extendedDiagnostics, and diff the numbers. ComponentPropsWithRef count via --generateTrace should show the jump.
Mitigation on our side: pinned to 6.4.2 for now.
Activity
litvinenko-rc commentedon Jul 8, 2026
I've noticed the same problem after updating from 6.4.2 to 6.4.3.
Downgrade from 6.4.3 to 6.4.2 produced the following results:
fix(types): cut type-instantiation cost for polymorphic styled compon…
fix(types): cut type-instantiation cost for polymorphic styled compon…
quantizor commentedon Jul 18, 2026
Sorry about this, it should be greatly improved in 6.4.4.
binhpv commentedon Jul 20, 2026
Following up with verification numbers for 6.4.4, since it was closed on the expectation that 6.4.4 fixes this. On our codebase the instantiation regression is partially fixed, but tsc peak memory and wall-time are not — 6.4.4 is actually the heaviest and slowest of the whole 6.4.x line for us.
Setup: a React component library (
styled-componentsused heavily across the lib), TypeScript 6.0.3,@types/react19.x. Same commit and lockfile, only thestyled-componentsversion swapped via the pnpm catalog. Each run cold (.tsbuildinfodeleted),tsc --noEmit --extendedDiagnostics,--max-old-space-size=8192, 2 runs per version. Structural metrics were bit-identical per version; peak RSS via/usr/bin/time -l(macOS).(tsc's own "Memory used" jitters with GC timing, so I'm reporting peak RSS as the stable memory signal; the "Memory used" figure showed the same trend, ~2.6 GB on 6.4.1 → ~3.96 GB on 6.4.4.)
What this shows:
Typesis now the highest of any 6.4.x (948K). So the "lower type-check memory and time" outcome doesn't hold here — 6.4.4 moved further from the pre-regression 6.4.2 baseline rather than back toward it. It looks like fewer instantiations were traded for larger/more-retained type objects.Concrete impact: our build pins tsc at
--max-old-space-size=3072; 6.4.1/6.4.2 fit comfortably, 6.4.4 OOMs withFATAL ERROR: ... JavaScript heap out of memory.Happy to run
--generateTraceand share the hot-symbol attribution if that would help localize where the remaining growth in 6.4.4 is concentrated.binhpv commentedon Jul 20, 2026
@quantizor I was too excited for memory usage reduction and ran the benchmark in our repo. However the result is not as expected. Please see comment above.
quantizor commentedon Jul 20, 2026
I'll do what I can but honestly we are dealing with inefficiencies in TS itself that are structural. I think the new Go version of TS should be significantly better and definitely recommend trying it.
develra commentedon Jul 20, 2026
Memory impact is still pretty rough - even on TS 7.0.2 - (tsgo).
Measured on TypeScript 7.0.2.
I'll stick with 6.4.2 for now - but really appreciate the work towards a solution.
quantizor commentedon Jul 20, 2026
Thanks @binhpv and @develra, this is helpful. I'll keep chipping away at it.
fix(types): cut consumer type-check cost for polymorphic components
fix(types): cut consumer type-check cost for polymorphic components (#…
quantizor commentedon Aug 4, 2026
Please try 6.5 when you get a moment! https://github.com/styled-components/styled-components/releases/tag/styled-components%406.5.0
quantizor commentedon Aug 6, 2026
There's a patch prerelease (
[email protected]) that fixes a few other issues if you could test it and let me know if it fixes your issue?quantizor commentedon Aug 7, 2026
Now formally released https://github.com/styled-components/styled-components/releases/tag/styled-components%406.5.1
Please go ahead and close the issue if it's fixed for you or post some more info.