-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 HeaderView component #31671
Conversation
@robertKozik Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Reviewer Checklist
Screenshots/VideosAndroid: Nativeios.native.movAndroid: mWeb Chromeandroid.web.moviOS: Nativeios.native.moviOS: mWeb Safariios.web.movMacOS: Chrome / Safariweb.movMacOS: Desktopdesktop.mov |
✋ 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 production by https://github.com/mountiny in version: 1.4.5-7 🚀
|
}, | ||
policy: { | ||
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, | ||
selector: (policy) => _.pick(policy, ['name', 'avatar', 'pendingAction']), |
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.
Question: doesn't this break the memoization (this is wrapped by memo()
) if this selector is always returning a new instance of the sub-object picked?
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.
We only pick some fields to prevent unnecessary re-render. Does this break something or cause regression?
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.
Does this break something or cause regression?
No that I know of, I just saw the code and got curious. I think it would be good to know if it makes the memo
completely useless. If it does, it may have been better to just return the complete policy object 🤷
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'm assuming that the implementation of memo
is not doing a deep comparison, it is just doing ===
, but maybe I'm wrong about that.
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 that fine because we are also using only memo
in other places without callback comparison.
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 that fine because we are also using only memo in other places without callback comparison.
It could also be wrong there... I guess I'll have to test it :P
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, let me know if it has any problem.
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 was able to test and I confirmed that I'm wrong, the memo
is working fine.
In case you are interested, I tested by adding this code in ReportScreen to force it to re-render every second
const [forceRerender, setForceRerender] = useState(0);
useEffect(() => {
setTimeout(()=>{
setForceRerender(forceRerender + 1);
}, 1000);
}, [forceRerender])
console.log('ReportScreen rerender', forceRerender);
and also added a console log in HeaderView
. I can see the ReportScreen rerender
every second, but HeaderView rerender
doesn't appear. If I remove the memo
, the HeaderView rerender
starts appearing every time ReportScreen
rerenders.
Details
Replace
withWindowDimensions
andwithLocalize
with the hook accordingly and subscribe current policy of the report instead of get all policies onHeaderView
to prevent unnecessary re-rendersFixed Issues
$ #30724
PROPOSAL: #30724 (comment)
Tests
Offline tests
Same as above
QA Steps
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(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)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
Android: Native
Screen.Recording.2023-11-22.at.12.05.02.mov
Android: mWeb Chrome
Screen.Recording.2023-11-22.at.11.55.12.mov
iOS: Native
Screen.Recording.2023-11-22.at.12.07.59.mov
iOS: mWeb Safari
Screen.Recording.2023-11-22.at.11.47.08.mov
MacOS: Chrome / Safari
web-1.mov
MacOS: Desktop
Screen.Recording.2023-11-22.at.12.14.56.mov