-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[No QA] Refactor Search component to use useMemo for data calculation #51480
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
[No QA] Refactor Search component to use useMemo for data calculation #51480
Conversation
| const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0; | ||
| const isSearchResultsEmpty = !searchResults?.data || SearchUIUtils.isSearchResultsEmpty(searchResults); | ||
| const prevIsSearchResultEmpty = usePrevious(isSearchResultsEmpty); | ||
| const data = searchResults === undefined ? [] : SearchUIUtils.getSections(type, status, searchResults.data, searchResults.search); |
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.
FYI: data was used as a dependency in a useEffect below, which caused the infinity loop (this component is not compiled because we ignore React rules 4 times, normally it would be taken care of)
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.
Thanks for the fix.
Two things come to mind:
- how come this did not surface previously?
- I just remembered that there is a
CONST.EMPTY_ARRAYfor similar cases 😅 butuseMemofeels better
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.
Those are great questions. I was asking myself the same thing since we didn't really change any behavior besides changing the react compiler.
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.
The only explanation I came up with is that Search component was somehow compiled before updating the library 🤔
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.
hey @blazejkustra @luacmartins I finally found some time to investigate this and try to understand why did it break.
The theory that Błażej posted above is 100% correct.
I have checked out on a commit before the introduction of the updated (bumped?) react-compiler and run healthcheck then. The component Search/index.ts was previously compiled without any problems. And I think this compilation and memoization is what prevented the bug.
Then I checked out onto a commit that was before this fix but after updating react-compiler - and Search is no longer compiled. So this is the reason in the past there was no infinite effect but now there was.
Finally you can test yourself that Search is also not compiled on newest main. Here is the reason:
Failed to compile src/components/Search/index.tsx:182:78. Reason: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
luacmartins
left a comment
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
Reviewer Checklist
Screenshots/VideosAndroid: Native51480-android-native.mp4Android: mWeb Chrome51480-android-web.mp4iOS: Native51480-ios-native.mp4iOS: mWeb Safari51480-ios-safari.mp4MacOS: Chrome / Safari51480-web.mp4MacOS: Desktop51480-desktop.mp4 |
ntdiary
left a comment
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. The original PR is interesting. I'll be studying it in more depth over the next few days, and observe any potential impacts it might have. 😄
mountiny
left a comment
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.
Thanks for a quick fix
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/luacmartins in version: 9.0.55-0 🚀
|
|
🚀 Deployed to production by https://github.com/Beamanator in version: 9.0.55-10 🚀
|
Details
Thanks to @Kicu we noticed a regression coming from react-compiler upgrade, on search page there was an infinite loop which caused the whole Search page to re-render indefinitely.
before.mov
Fixed Issues
$ #49393
$ #51505
PROPOSAL: N/A
Tests
Maximum update depth exceedederrorsOffline tests
N/A
QA Steps
N/A
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel so the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
MacOS: Chrome / Safari
after.mov