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
Currently, there are optional features that are part of components that add a bunch of bundle size even if not used. trackCursorAxis on Tooltip is one such example.
If we want to add more features to Tooltip like truncation logic, inline() logic, etc, this adds further cost but most users don't need that by default and shouldn't need to incur.
One possible solution is a features prop where you pass in 'features' using imports so bundlers can remove them if they aren't called:
I posted this in our Discord with respect to avoiding a monolithic Menu, and it made me think of more things we can split out as "feature components".
Some of the benefits of splitting components include:
Better tree-shaking: if a component handles everything via props, it can't be treeshaken by your bundler compared to a separate component
Props/types can be easier: ContextMenu for example doesn't support a bunch of the props that Menu does (modal, openOnHover, delay, etc.) So if you try to configure both simultaneously, it can be confusing. (We have this problem in a couple places currently, namely with the Select positioning.) It can be easier to type MultiSelect value to always be an array; same with RangeSlider
Here are some other possible ones — features as components:
Since the regular anchoring props don't apply when alignItemWithTrigger=true (except in fallback/touch mode), it could make more sense to split it out, removing the cost of it when you don't use it.
Menu, Popover openOnHover and related delay features. Since delay doesn't work without openOnHover it again might make more sense to split it out, also removing the cost of it if unused.
This is similar to the features prop but it adds a bit more clarity as its used directly on the component this affects. If the alignItemWithTrigger feature has any additional options which customize the feature, they can also be passed here.
This would also "group" properties that are bound to a certain feature.
A cool side effect of this pattern would be that features could have different implementations and all of them could be treeshakeable.
With this pattern one can add features globally to certain components. Each of the features represents the whole implementation of the features, additional options for each feature are provided directly via component props. If a prop is used and the underlying feature is not provided the prop would do nothing and a warning / error could be printed.
An extension to such an API could also be to have lazy features. This would be "nice to have" features that don't influence the core functionality of a component but are costly in implementation. Something like Select.alignItemWithTrigger would be a good example. This approach would use promises, so any lazy feature would only be available if the promise is resolved.
An unwanted side effect of that would be that the component would change its behavior depending on whether the feature is available or not. (In the case of alignItemWithTrigger the first opening of the select wouldn't have the feature applied, but subsequent opening could have the feature)
Activity
atomiks commentedon May 30, 2025
I posted this in our Discord with respect to avoiding a monolithic
Menu, and it made me think of more things we can split out as "feature components".Here are some other possible ones — features as components:
Since the regular anchoring props don't apply when
alignItemWithTrigger=true(except in fallback/touch mode), it could make more sense to split it out, removing the cost of it when you don't use it.Menu, Popover
openOnHoverand relateddelayfeatures. Sincedelaydoesn't work withoutopenOnHoverit again might make more sense to split it out, also removing the cost of it if unused.This API reminds me a bit of composable chart libraries where features are added as component parts separately.
KingSora commentedon Jun 16, 2025
@atomiks this feature is a very good idea!
I would like to add patterns on how to solve this problem:
This is similar to the
featuresprop but it adds a bit more clarity as its used directly on the component this affects. If thealignItemWithTriggerfeature has any additional options which customize the feature, they can also be passed here.This would also "group" properties that are bound to a certain feature.
A cool side effect of this pattern would be that features could have different implementations and all of them could be treeshakeable.
With this pattern one can add features globally to certain components. Each of the features represents the whole implementation of the features, additional options for each feature are provided directly via component props. If a prop is used and the underlying feature is not provided the prop would do nothing and a warning / error could be printed.
An extension to such an API could also be to have lazy features. This would be "nice to have" features that don't influence the core functionality of a component but are costly in implementation. Something like
Select.alignItemWithTriggerwould be a good example. This approach would use promises, so any lazy feature would only be available if the promise is resolved.An unwanted side effect of that would be that the component would change its behavior depending on whether the feature is available or not. (In the case of
alignItemWithTriggerthe first opening of the select wouldn't have the feature applied, but subsequent opening could have the feature)[-]Optional features tree-shaking[/-][+][tooltip] Optional features tree-shaking[/+]