Repository navigation
[AvatarGroup] Fix AvatarGroup typescript performance when using slotProps - #49213
Conversation
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
|
@claude review |
PR reviewThis is a one-line, type-only change to Tests (1)1. 🟠 Public slot-props contract changed with no type testLocation: <AvatarGroup component="ul" />;
<AvatarGroup variant="circular" />;
// ...nothing exercising slots / slotPropsThe PR narrows a public type and the only thing that can catch a regression here is Failure scenario: A future refactor of Fix: Add positive and negative assertions to <AvatarGroup slotProps={{ surplus: { variant: 'rounded', className: 'x' } }} />;
<AvatarGroup slotProps={{ surplus: (ownerState) => ({ variant: ownerState.variant }) }} />;
// @ts-expect-error
<AvatarGroup slotProps={{ surplus: { nonExistentProp: true } }} />;Simplifications (2)1. 🟡 Type argument list should collapse to one line after the changeLocation: surplus: SlotProps<
typeof Avatar,
AvatarGroupComponentsPropsOverrides,
AvatarGroupOwnerState
>;The multi-line break was only needed because the old type argument was long. Collapsed, the line is ~98 characters — under the 100-column Failure scenario: CI lint fails on an otherwise-green one-line PR, costing a round trip. Fix: surplus: SlotProps<typeof Avatar, AvatarGroupComponentsPropsOverrides, AvatarGroupOwnerState>;2. ℹ️ The expensive expansion is only partly removedLocation: fallback: SlotProps<
React.ElementType<SvgIconProps>,
AvatarFallbackSlotPropsOverrides,
AvatarOwnProps
>;
Failure scenario: The PR's measured improvement is smaller than expected, and the next Fix: Out of scope for this PR, but worth a follow-up applying the same VerdictApprove after nits — the type substitution is correct and effectively behavior-preserving; only the Prettier reflow and the missing 🤖 Review generated with Claude Code · Opus 5 (High) · |
|
All issues from claude review is resolved, except for 2nd point. If approach in this PR is fine for reviewers, i'll create same PR for other components |
The AvatarGroup surplus slot defaults to Avatar, but its props type uses React.ElementType. This unnecessarily checks AvatarProps against every HTML/SVG element. Use typeof Avatar directly, matching the runtime implementation.
Performance Gain
For:
<AvatarGroup slotProps={{ surplus: {} }} />TypeScript instantiations decrease from
39,431 to 15,827approximately `60% fewer.I got above number from running
tsc --noEmit --extendedDiagnostics