-
Notifications
You must be signed in to change notification settings - Fork 65
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
fix(component): performance improvements for Dropdown/Select components #475
Conversation
aff89fc
to
d6b06b9
Compare
d6b06b9
to
2fb2c70
Compare
} | ||
</Reference> | ||
isValidElement(toggle) && | ||
cloneElement<React.HTMLAttributes<any> & React.RefAttributes<any>>(toggle as any, { |
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.
This can be reduced to this:
cloneElement<React.HTMLAttributes<any> & React.RefAttributes<any>>(toggle as any, { | |
cloneElement(toggle, { |
import { StyledBox } from './styled'; | ||
import { DropdownItem, DropdownLinkItem, DropdownProps } from './types'; | ||
|
||
import { DropdownItemGroup } from '.'; |
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.
Let's import this from ./types
above.
isAction = false, | ||
...props | ||
}) => { | ||
type Items = DropdownItem | DropdownLinkItem | SelectOption<unknown> | SelectAction; |
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.
I think you can add a generic to Items
type Items = DropdownItem | DropdownLinkItem | SelectOption<unknown> | SelectAction; | |
type Items<T> = DropdownItem | DropdownLinkItem | SelectOption<T> | SelectAction; |
|
||
export const List = memo( | ||
forwardRef<HTMLUListElement, ListProps>((props, ref) => <StyleableList {...props} forwardedRef={ref} />), | ||
forwardRef<HTMLUListElement, ListProps<unknown>>((props, ref) => <StyleableList {...props} forwardedRef={ref} />), |
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.
Can we add a comment on why we need this unknown
?
90e1459
to
95f11b1
Compare
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.
Looks good, one last 🍹 comment. I would also get 1 more set of 👀 on this.
@@ -3,7 +3,7 @@ import { theme as defaultTheme } from '@bigcommerce/big-design-theme'; | |||
import { hideVisually } from 'polished'; | |||
import styled, { css } from 'styled-components'; | |||
|
|||
import { StyledButton } from '../Button/styled'; | |||
import { StyleableButton } from '../Button/Button'; |
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.
🍹
import { StyleableButton } from '../Button/Button'; | |
import { StyleableButton } from '../Button/private'; |
403e2d8
to
26edce4
Compare
We're looking for one more set of eyes @bigcommerce/frontend |
{ | ||
name: 'eventListeners', | ||
options: { | ||
scroll: isOpen, |
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.
nice
There is an issue with Downshift and memoized components. I have opened a PR for a potential fix, I would advise not to merge until the fix is released. downshift-js/downshift#1205 |
78a8d72
to
e434adb
Compare
e434adb
to
4672aab
Compare
What
Long time coming, but we noticed every single item would rerender whenever hovering an option, so we knew performance could be improved.
This changes fix that by memoizing the props that were triggering a rerender, thus only items with true changes will rerender. I added some props to some components for feature parity (like groups to MultiSelect). A lot of things were moved around, hoping this helps with clarity of these components.
Some area of opportunity:
as
. Let me know if we can fix them some other way!useMultipleSelection
downshift hook.Screenshots