Skip to content

[core] Bundle size improvements #1246

Open
@atomiks

Description

@atomiks

Inspecting the production bundle with create-vite-app using @base-ui-components/react reveals some areas of improvement:

  1. Extra prop-types logic is included in the final bundle: Even though .propTypes assignments are removed in prod, there's some extra code related to it when inspecting the bundle. We should remove prop-types entirely if possible in the final build, and only use it for documentation
  2. Minified errors: Context error messages aren’t minified for production, we can use a simple short/reusable message for production instead
  3. Duplicated logic between Floating UI and Base UI: Another version of mergeReactProps is used in useInteractions, so we should re-create useInteractions to use our own version instead of importing it. There is also duplicated logic between our internal Composite component and useListNavigation. There's also a duplicated version of useId
  4. Needless destructuring and re-passing of variables: we can pass the whole object in most cases, reducing unnecessary variable assignments. This is done for some components but not others
  5. Avoid unnecessary dependencies: importing only Dialog needlessly includes all anchor positioning logic since useFloating() brings it in. If FloatingFocusManager can accept floatingRootContext object, then that hook won’t need to be used. Importing only Tooltip needlessly includes the tabbable dependency and related focus guard logic since FloatingPortal brings it in. This matters less if you're using multiple components, however, since this logic will be brought in at some point anyway

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreInfrastructure work going on behind the scenesimprovementThis is not a bug, nor a new featureperformanceumbrellaFor grouping multiple issues to provide a holistic view

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions