RFC: Performatic Component Model #552
Replies: 7 comments 4 replies
-
About the type handle, doing like that will work for every component: type ComponentProps = React.ComponentPropsWithRef<'{element}'> & ComponentOptions Maybe we can check if this is the best approach or if we can improve this by making it easier to apply the elements props |
Beta Was this translation helpful? Give feedback.
-
What do you think of avoiding using IMO all of Ariakit's necessary props should be embedded into the |
Beta Was this translation helpful? Give feedback.
-
I think that styling and component model are tightly coupled. What do you think about joining both discussions here? |
Beta Was this translation helpful? Give feedback.
-
It can be as simple as this: https://github.com/vtex/admin-ui/blob/f21ea46c0a3f38ed997a65bfc2ce82cc15cb0ced/packages/admin-ui/src/modal/util.ts#L9 |
Beta Was this translation helpful? Give feedback.
-
Does still make sense to have the polymorphism as it was before? ( So my proposal is to have a polymorphism only for specific behaviors. ( |
Beta Was this translation helpful? Give feedback.
-
The RFC is approved by the team |
Beta Was this translation helpful? Give feedback.
-
@matheusps Can we close this? Have we already done all the changes we intended? |
Beta Was this translation helpful? Give feedback.
-
RFC Performatic Component Model
Problem
Admin ui's components using the current component model are slow. While investigating table performance issues we found that rendering components using createComponent/useElement is less performatic than rendering native components (link to investigation report). The perfomance loss was impactful enough that it degraded the overall performance of the page when using admin-ui.
Why this matters?
The current components we provide are degrading the performance of our users pages, specially on pages with many components rendered and many re-renderings (like when using tables). Improving our architecture to be more performatic will improve responsiveness and drastically improve user experience on admin pages that use admin-ui.
Proposal
Stop using
createComponent
anduseElement
to create every component, rebuild components with alternative solutions to handle the points createComponent/useElement currently does.Points handled by current component model:
Parsing csx object
useElement
handles merging of base component style (our native styling) and users custom style added tocsx
prop.Injecting forward refs
createComponent
injects forward refs, witch is something we must do for all our components.Typing simplification
createComponent
simplifies the process of typing the component with a merge of native components forwarded props + additional props + default admin-ui props (like csx or as)Polymorphism
when using
useElement
the resulting component always accepts the propas
and handles polymorphism.New suggested architecture:
Removing the csx prop from all components, handle custom styles through
classNames
props, pre-parsed by the user with acsx
function provided by us through a different package. Merge our native classnames and users classnames withcx
. more on: #536Handle ref forwarding on each components implementation with reacts
forwardRef
. Type components the traditional way. Not every component will have polymorphism (as
prop) to reduce code complexity and improve performance.Styling
Components will receive additional custom styling through
className
propInternally, base classNames will be built outside the component scope to improve performance, variant that affect the style will be forwarded as a
data-
attribute. Variants will be styled via css with data attribute selectors. An auxiliary function can be used to generate the selectors text to simplify implementation.Forward refs
Handle forward refs the "react way", inside each components main file.
Typing
Type the components props the vanilla way, extending the native/base components props and creating a separate type for each variant.
Pros
Cons
user custom styling:
Unresolved questions
Polymorphism implementation details?Function to simplify writting data attibute selector string?No tests comparing performance between modelsHow do we decide when a component should be polymorphic?Next steps
References
Beta Was this translation helpful? Give feedback.
All reactions