-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Slots: Move slot options to new 'slots' prop #8868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Component perf results:
|
Overall I like it. Instead of this: {
slots: {
root: {
component: Foo
}
}
} Could we simplify? {
slots: {
root: Foo
}
} |
I still think we want to support an expandable slot options bag. This PR just moves it. Components have the signature: component: (props: TProps, context?: any) => ReactElement | null; While render functions have the signature: render: (props: TProps, component: ComponentType<TProps>) => ReactElement | null; It is not possible to differentiate between them via typing or at run time. I think it's a good idea to have them separated to prevent us from stomping or conflicting with the use of |
Another idea, make the type of the slot: That way both work: {
slots: {
upButton: UpButton,
downButton: {
render: (p, C) => <Tooltip><C {...p} /></Tooltip>
}
}
} If your goal is to just render something different, the API is clean and simple. If your goal is to wrap stuff, we can support alternative, more verbose ways. I think the common case is the replace, while the wrapping scenario is a minority. |
Yes, but we will lose all type safety. That's the fault of TS3.x regression on top of some issues with unions. I'd rather wait to add this until TS3.5 is released (which would be a backwards compatible change.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love it!
Pull request checklist
$ npm run change
Description of changes
Due to some thoughts I had while implementing #8754 reinforced by further discussion on said PR, I've decided to make some changes regarding slot options.
Fundamentally slot props are overloaded allowing both "what to render" and "how to render" to coexist in the same props object. However, this approach creates additional friction by merging "what" and "how" into the same complex object. It also prevents devs from using shorthand when providing any slot implementation.
This PR creates a new
slots
prop that is automatically added to components through a helper interface. Thisslots
prop now contains the slot options for all of the slot props identified for the component.This change will also make it a bit harder to impact perf negatively when using props and slots by minimizing need to instantiate complex objects and more easily allowing use of constant objects.
Slots API
Before:
Slots interface before:
After:
Practical Examples
Before:
After:
Before
After
Focus areas to test
(optional)
Microsoft Reviewers: Open in CodeFlow