-
Notifications
You must be signed in to change notification settings - Fork 325
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
chore: enable rules of hooks for RN chat SDK #2626
Conversation
SDK Size
|
@@ -25,11 +25,13 @@ export const useViewport = (rounded?: boolean) => { | |||
return () => subscriptions?.remove(); | |||
}, []); | |||
|
|||
// eslint-disable-next-line react-hooks/exhaustive-deps |
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.
are these false positives? curious why the script detects these as hook deps :)
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.
Not too sure why the eslint-disable-next-line
happens here either (instead of useMemo
itself), but they're essentially here because useMemo
is invoked every time and these aren't memoized at all (defined inline, will change on every render), while consuming resources as React
memoization does. It's probably because if we want to actually memoize these, we should either:
- Move the function definitions inside of the
useMemo
(and make it depend onviewportDimensions.height
/viewportDimensions.width
- Wrap the definitions within
useCallback
(with their respective dependencies ofwidth
/height
), while getting rid ofuseMemo
altogether
In my opinion these shouldn't be subject to memoization at all since I'm pretty sure the memoization itself is more expensive than directly setting them to some state (within the event listener) and just passing them like so. But we can do it incrementally and see what sticks.
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.
That is, assuming some downstream project doesn't actually rely on the fact that these aren't memoized :D that might be a bit tricky
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 it would be best if we remove useMemo(() => ({ vh, vw }), [vh, vw]);
and return directly.
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.
Yep, after I'm done with some other things I'll jump into taking care of these easier low hanging fruits which should improve performance a bit.
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 catch here, this useMemo does nothing here, useCallback for both vw and vh and then remove useMemo here
I think vw and vh is used in multiple React.Memos
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.
Yep, I'll have to look how far the non-memoization cascades here. Also I hope that some downstream implementations do not do not rely on the fact that vh
and vw
aren't memoized and that we break them. Should we add this somewhere ?
🎉 This PR is included in version 5.36.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎯 Goal
As @santhoshvai pointed out in this Slack thread, the Rules of Hooks
eslint
plugin has been disabled for the Chat SDK. We want to re-enable it so that future development follows these rules intrinsically.🛠 Implementation details
This is mostly a port of GetStream/stream-chat-react#2244 (thanks @myandrienko !) to our SDK.
Brief rundown of the steps:
react-hooks/exhaustive-deps
pluginyarn eslint 'src/**/*.{js,ts,tsx,md}' -f json -o lint.json
in all directories for which the plugin was enabledconst json = require('./lint.json');
to whichever path yourlint.json
files got generated at)yarn prettier --write
to fix all of the formatting issuesyarn eslint
again to make sure that no warnings pop up after the script had been runCare that
prettier
might also do some other changes in additional files - everything was checked by hand as well after the script was run and odd edge cases were handled adhoc (in my case they were onlyprettier
ones).🎨 UI Changes
iOS
Android
🧪 Testing
☑️ Checklist
develop
branch