Repository navigation
[autocomplete] Fix TypeScript performance when using slotProps - #49634
Open
devbite-enzo wants to merge 1 commit into
Open
devbite-enzo wants to merge 1 commit into
devbite-enzo wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deploy previewBundle size
PerformanceNo regressions in 32 benchmarks · ran 3m 55s · details Check out the code infra dashboard for more information about this PR. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(https://github.com/mui/material-ui/blob/HEAD/CONTRIBUTING.md#sending-a-pull-request).
Same issue as #49213, in Autocomplete.
The
chip,clearIndicator,paper,popperandpopupIndicatorslot props are typed asSlotProps<React.ElementType<Partial<XProps>>, …>. Every prop ofPartial<XProps>is optional, so it fits almost every intrinsic element.React.ElementType<…>then expands to a union of ~476 HTML/SVG tags, andSlotComponentPropsbuilds the props of each one. Whenever two differentAutocompletePropsinstantiations are compared, TypeScript has to measure the variance of all six type parameters through these unions. That happens with wrapper components that spread props orslotProps, which is the common pattern for form-library wrappers.This PR types the slots by the component they render, as #49213 did for AvatarGroup.
IconButton,PaperandPopperusetypeof Component.chipusesReact.JSXElementConstructor<Partial<ChipProps<ChipComponent>>>so it keeps theChipComponentgeneric. That matches howAutocompleteSlotsalready types the same slots.Performance gain
A wrapper in the usual shape:
tsc --noEmit --extendedDiagnosticson that file alone, insidepackages/mui-material:In a production Next.js app (~1,400 source files, TypeScript 7), computing the variance of
AutocompletePropstook 2.9 s per checker. A fulltsc --noEmitwent from 20.9 s / 63 s CPU / 7.3 GB to 13.1 s / 29 s CPU / 3.0 GB with this change applied as a local patch (and--checkers 2). Since tsgo computes the variance in each checker separately, the cost multiplies with parallelism.Compatibility
The props each slot accepts are unchanged, including
componentonpaper. Only the props of unrelated intrinsic elements drop out of the union. The new spec cases cover the accepted props and the rejection of unknown ones.pnpm proptypesandpnpm docs:apiproduce no changes.🤖 Generated with Claude Code