-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
refactor(suite/components): improve typing and performance of the VirtualizedList #16592
Conversation
@@ -90,7 +90,7 @@ export const SelectAssetModal = ({ | |||
badge, | |||
contractAddress, | |||
shouldTryToFetch, | |||
}: AssetProps) => ( | |||
}) => ( |
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.
No need here anymore, due to generic types work properly.
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.
TODO: add type tests here
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.
✅
} | ||
|
||
// NOTE: typecast here + memo() and forwardRef() because of passing the ref for useShadow() | ||
export const VirtualizedList = memo( |
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.
Unfortunatelly, memo()
and forwardRef()
eat the generic. This can be bypassed with typecast, but that kills passing of the ref. I think it should be possible to create some type helper for it, altough I am not sure if it makes sense here to dive that deep.
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.
Pls advice, if you have any idea why direct passing of the ref
prop doesn't work and I am forced to use the forwardRef
again, thanks
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.
Sorry, no idea 🤷♂️
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 could have been, it, but it doesnt matter anymore.
onScroll?: (e: Event) => void; | ||
onScrollEnd: () => void; | ||
listHeight: number | string; | ||
listMinHeight: number | string; | ||
ref?: React.Ref<HTMLDivElement>; |
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.
Unfortunatelly, due to typecast, this needs to be here to prevent TS errors.
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.
Oh yeah, forwardRef
will be deprecated https://react.dev/reference/react/forwardRef
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.
yeah, this could have been better solution.
🚀 Expo preview is ready!
|
9e94a54
to
b51c7e1
Compare
b51c7e1
to
1f876c0
Compare
… by memoizing VirtualizedList while mantaining type safety
…n VirtualizedList component
1f876c0
to
edacb7c
Compare
@@ -22,6 +24,7 @@ | |||
"@suite-common/suite-constants": "workspace:*", | |||
"@suite-common/suite-utils": "workspace:*", | |||
"@suite-common/validators": "workspace:*", | |||
"@testing-library/jest-dom": "^6.6.3", |
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.
for some reason, linter forced me to put it here
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.
LGTM and I really like you added tests.
I'm not 100% sure about changes in the logic, but tested and it works fine 👍
} | ||
|
||
// NOTE: typecast here + memo() and forwardRef() because of passing the ref for useShadow() | ||
export const VirtualizedList = memo( |
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.
Sorry, no idea 🤷♂️
TODO
Add tests for:
Description
VirtualizedList didn't have the proper generic types passed on due to forwardRef(). The
forwardRef()
is apparantly needed due touseShadow()
. I tried to pass theref
manually, but the shad was broken.However, with typecast, types work and shadow too. Also, I added few perf improvements and simplify
Changes
Screenshots: