You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 00b9ee2
Browse filesBrowse the repository at this point in the historyBrowse files
* fix(types): cheaper annotated declaration sites, and narrow generic polymorphic props
Two independent type fixes, each with its own changeset:
- Rebase the widened inline `style` prop on `React.CSSProperties` so an explicit
`IStyledComponentBase`/`IStyledComponent` annotation, which isolatedDeclarations
and `.d.ts`-emitting packages must write, relates against a shared csstype
instantiation instead of walking csstype per component. About 21% fewer types
created at annotated declaration sites, with no behavior or call-site change.
- Gate the style widening off for a prop bag carrying a string index signature,
so `styled()` wrapping a generic polymorphic component keeps its declared props
narrow instead of collapsing them to `any` under built-in `Omit` (#5756).
Also adds an `annotated` kind to the consumer type-perf fixture so the
declaration-site annotation axis is guarded going forward.
* perf(types): `.attrs` target-unchanged fast path, and broaden the type-perf fixture
- Skip re-resolving the render target's props when object-form `.attrs()` leaves
the target unchanged (the common case). That path rebuilt the ~265-key
intrinsic prop bag through `ComponentPropsWithRef` on every `.attrs` call, only
to reproduce what `OuterProps` already held; the fast path returns it directly.
About 6.8% fewer consumer type-check instantiations, with no change to the
resulting component's accepted props. Redirecting the target (`.attrs({ as })`,
including the function form) is unaffected.
- Add four exotic fixture kinds, each pricing a `types.ts` conditional arm no
existing kind reached and each doubling as a compile-fail canary:
`permissiveFactory` (the un-introspectable `WidenUntypedProps` fallback),
`genericPoly` (the #5756 `string extends keyof P` `OverrideStyle` gate),
`attrsAsRedirect` (function-form `.attrs` union-target seam), and
`disjointTarget` (the `keyof B extends never` empty-bag guard). Plus `style` and
`ref` call-site variants on `plainTag`, and `canary.tsx` pins for the two #5756
soundness properties. The budget was re-measured; the growth is the fixture, not
the cost.
* perf(types): distribute `MakeAttrsOptional` over built-in `Omit`
The largest single cost of `.attrs` on a tag is `MakeAttrsOptional`'s mapped pass
over the ~266-key widened intrinsic bag (~30% of that kind's types), not the
target-redirect seam: a union redirect and a single-concrete redirect price
identically, and collapsing the `ComponentPropsWithRef` re-merge moves ~6 types
while breaking four redirect contracts.
Switch that pass from `FastOmit` to built-in `Omit` distributed through an outer
`P extends unknown`. Built-in `Omit` is the more optimized here (the same result
the `OverrideStyle` note records), and the distribution runs it per union member
so a union-props attrs target (`styled(Pressable).attrs(...)`) keeps its
member-specific keys instead of collapsing to the union's common ones; a bare
undistributed `Omit` drops `href`.
Consumer fixture: -7.5% types, -4.1% instantiations, memory flat. Contract suite
(web + native) and every `.attrs` form (object, function, as-redirect, chained,
union-target) unchanged.
Two costs on the `.attrs` path are gone. Object-form `.attrs()` left the rendered target unchanged but still re-resolved that target's whole prop bag on every call, making `.attrs` on an HTML or SVG tag far costlier than on a wrapped component; it now reuses the props already resolved for the tag. Separately, making attrs-provided keys optional ran an avoidably expensive pass over the target's full prop set on every attrs component. Together these cut consumer type-check work measurably across every `.attrs` form, with no change to the resulting component's accepted props. Redirecting the target with `.attrs({ as })`, including the function form, is unaffected.
Assigning a styled component to an explicit type, as `isolatedDeclarations` and any package that emits `.d.ts` files must (`const Button: IStyledComponentBase<'web', ...> = styled.button``), used to be several times more expensive to check than an inferred one, because the annotation's `style` and the component's widened `style` were two different csstype representations that the checker compared property by property.
8
+
9
+
The inline `style` widening now builds on React's own `CSSProperties`, the same type a hand-written annotation carries, so that comparison short-circuits. On a 40-component fixture this cut the types created for the annotated pattern by about 21%, with no change to what `style` accepts: CSS custom properties, a component's own narrow `style`, and `style={undefined}` all behave exactly as before.
`styled()` wrapping a generic polymorphic component keeps its declared props narrow.
6
+
7
+
Wrapping a component whose props are generic over an element type, such as the common `<C extends React.ElementType>(props: PolymorphicProps<C, OwnProps>)` pattern, used to let the styled result accept prop values the component itself rejects: `styled(Button)` would take `variant="anything"` even though `<Button variant="anything">` is a type error. The wrapper now narrows those props exactly as the direct component does, so a bad value is caught in both places. Valid props, children, and plain (non-generic) targets are unaffected.
0 commit comments