-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[No QA] Refactor Search component to use useMemo for data calculation #51480
Conversation
@@ -196,7 +196,13 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr | |||
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_ARRAY
for similar cases 😅 butuseMemo
feels 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)
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 |
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. 😄
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 exceeded
errorsOffline tests
N/A
QA Steps
N/A
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
MacOS: Chrome / Safari
after.mov