Skip to content
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

Fix comment linking bugs #46315

Merged
merged 10 commits into from
Aug 19, 2024
Merged

Conversation

janicduplessis
Copy link
Contributor

@janicduplessis janicduplessis commented Jul 26, 2024

Details

This includes a few fixes for fixing janky or stuck scroll after comment linking. There were actually multiple different issues all with separate fixes. After all those scroll is now smooth and doesn't get stuck.

  1. Fix onStartReached not called in some cases (15546b6): When scrolling down after comment linking, sometimes the scroll would get stuck. This is because onStartReached was never called. This is caused by the early return in VirtualizedList.getDerivedStateFromProps. It compares the number of items with renderMask.numCells(), but for some reason sometimes this is different from the previous number of items. So to fix it we now save the previous number of items in state and also compare that. Upstream PR Fix onStartReached not called facebook/react-native#46250

  2. Fix maintainVisibleContentPosition on Android (0b214f7): I found a few issues with the maintainVisibleContentPosition implementation on Android, which causes some jumping while scrolling. Part of it was already addressed in Fix maintainVisibleContentPosition on Android during momentum scroll facebook/react-native#43425, but we didn't have a patch for it so this adds it. There is also another issue where the first visible view is sometimes incorrectly updated so it moves the update to when the scroll view scrolls, instead of before views are updated. I also found an issue because we use z-index on list cells which cause views to be re-ordered and the wrong view ends up being selected as the first visible view. Upstream patch maintainVisibleContentPosition fixes on Android facebook/react-native#46247.

  3. Fix newer messages not loading (5f9aede): There is a check in loadNewerChats that would sometimes cause scrolling to be stuck because new messages are not loaded. I verified with the author of this code @perunt and also did some testing and we concluded that this code is no longer needed and can be removed.

  4. Fix not found view flicker (c804881): Some code relies on the isLinkingToMessage variable to not display the not found view, but it is currently updated in a useLayoutEffect. On web this works fine, but on native it cannot render synchronously so there will be a flicker of the wrong UI. To fix this we can update state in render instead.

  5. Fix scrollTo called when not needed on Android (13c9acb): This code is supposed to call scroll to only when the screen is focused, but it was being called more because the callback depended on the scroll position value, so every time scroll ends it would call scroll to. This caused issues sometimes where scroll position would become incorrect because it would scroll to an outdated position and revert the scroll caused by maintainVisibleContentPosition. To fix this we can remove the dependency on the scroll position of the callback by using a ref.

  6. Fix flickering on iOS, this is caused by the patches/react-native+0.73.4+016+iOSCoreAnimationBorderRendering.patch patch which adds a CATransaction around mounting phase. This transaction should also include the willMount and didMount observer calls since we use those to adjust the scroll position and we don't want iOS to update the screen before those are called. This moves the CATransaction creation around the code that calls the observers.

Known issues left, will address in another PR:

  1. On android when comment linking twice to the same message, on the 2nd time the scroll position jumps incorrectly.

Before

Scrolling after comment linking with cache:

This shows janky scroll and scroll getting stuck.

Screen.Recording.2024-08-01.at.18.22.46.mov

Scrolling after comment linking no cache:

This shows the flicker of not found view as well as scroll being stuck.

Screen.Recording.2024-08-01.at.18.33.31.mov

After

Scrolling after comment linking with cache:

Screen.Recording.2024-08-01.at.14.32.36.mov

Scrolling after comment linking no cache:

Screen.Recording.2024-08-05.at.16.49.22.mov

Fixed Issues

$ #46217
$ #46222
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  • Verify that no errors appear in the JS console
  • Test comment linking flow with cached messages (scroll through the full chat first)
  • Test comment linking flow without cached messages (use clear cache in Troubleshoot section)

Comment linking flow:

  • In a chat with many messages copy the link to a message and send it
  • Click on the message link from the first step
  • Verify that the right message is scrolled to and that it is possible to scroll back down to the start of the chat

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2024-08-01.at.14.32.36.mov
Android: mWeb Chrome
Screen.Recording.2024-08-05.at.17.00.52.mov
iOS: Native
Screen.Recording.2024-08-05.at.17.21.01.mov
iOS: mWeb Safari
Screen.Recording.2024-08-05.at.17.24.16.mov
MacOS: Chrome / Safari
Screen.Recording.2024-08-05.at.16.47.10.mov
MacOS: Desktop
Screen.Recording.2024-08-05.at.17.11.03.mov

@janicduplessis janicduplessis changed the title Fix onStartReached not called in some cases Fix comment linking bugs Jul 27, 2024
@janicduplessis janicduplessis force-pushed the @janic/fix-osr branch 3 times, most recently from 0740e00 to 7b35f0f Compare August 1, 2024 18:39
@janicduplessis janicduplessis marked this pull request as ready for review August 5, 2024 21:31
@janicduplessis janicduplessis requested a review from a team as a code owner August 5, 2024 21:31
@melvin-bot melvin-bot bot requested review from ishpaul777 and removed request for a team August 5, 2024 21:31
Copy link

melvin-bot bot commented Aug 5, 2024

@ishpaul777 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]

@ishpaul777
Copy link
Contributor

ishpaul777 commented Aug 6, 2024

i'll priortize this today 🙇

@ishpaul777
Copy link
Contributor

ishpaul777 commented Aug 6, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
WhatsApp.Video.2024-08-11.at.1.57.47.AM.mp4
Android: mWeb Chrome
WhatsApp.Video.2024-08-11.at.1.49.40.AM.mp4
iOS: Native
trim.7408C1CB-CB69-4B81-AAF5-0379D64FC0A8.MOV
iOS: mWeb Safari
Screen.Recording.2024-08-17.at.1.29.52.AM.mov
MacOS: Chrome / Safari
Screen.Recording.2024-08-17.at.1.02.14.AM-2.mov
MacOS: Desktop
Screen.Recording.2024-08-17.at.1.49.13.AM-1.mov

@ishpaul777
Copy link
Contributor

ishpaul777 commented Aug 6, 2024

I still got stuck for few seconds, while scrolling after commentlinking 🤔 (cached messages)

Record_2024-08-07-01-13-32.mp4

cc @janicduplessis

@ishpaul777
Copy link
Contributor

ishpaul777 commented Aug 6, 2024

Fix scrollTo called when not needed on Android (13c9acb): This code is supposed to call scroll to only when the screen is focused, but it was being called more because the callback depended on the scroll position value, so every time scroll ends it would call scroll to. This caused issues sometimes where scroll position would become incorrect because it would scroll to an outdated position and revert the scroll caused by maintainVisibleContentPosition. To fix this we can remove the dependency on the scroll position of the callback by using a ref.

I am not sure if i understand the issue itself, could you please provide a after/before video. is this part of Scrolling after comment linking with cached actions issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java code is way over my head, i'll bring in a internal engineer later to help review this. Would be helpful if you can add a before/after video

@janicduplessis
Copy link
Contributor Author

@ishpaul777

I still got stuck for few seconds, while scrolling after commentlinking 🤔 (cached messages)

Do you have to scroll up / down to unblock it or just wait? The rendering of new items is just a bit slow, especially in dev mode so it would be normal if it just stays stuck for a little bit of time. It would be good to profile though to see if it can be optimized.

I am not sure if i understand the issue itself, could you please provide a after/before video. is this part of Scrolling after comment linking with cached actions issue

It is part of Scrolling after comment linking with cached actions issue. Sometimes the scroll position would jump when the following occurs:

  1. Scroll ends -> JS sends new scroll position to native
  2. New messages are loaded
  3. Native adjusts scroll position to maintain visible content position
  4. Native receives outdated scroll position from JS (step 1) and scroll to old position which causes jumping

Java code is way over my head, i'll bring in a internal engineer later to help review this. Would be helpful if you can add a before/after video

You can kind of see it in Scrolling after comment linking with cache: before and after videos. Basically before the patch sometimes there will be jumping of content. Would you like me to make a video with just that java change to see the before / after?

@ishpaul777
Copy link
Contributor

I am not sure if i understand the issue itself, could you please provide a after/before video. is this part of Scrolling after comment linking with cached actions issue

It is part of Scrolling after comment linking with cached actions issue. Sometimes the scroll position would jump when the
following occurs:

  1. Scroll ends -> JS sends new scroll position to native
  2. New messages are loaded
  3. Native adjusts scroll position to maintain visible content position
  4. Native receives outdated scroll position from JS (step 1) and scroll to old position which causes jumping

Is this the jump you are talking about 🤔 (this is on main branch)

WhatsApp.Video.2024-08-08.at.2.10.58.AM.mp4

@ishpaul777
Copy link
Contributor

ishpaul777 commented Aug 7, 2024

Do you have to scroll up / down to unblock it or just wait? The rendering of new items is just a bit slow, especially in dev mode so it would be normal if it just stays stuck for a little bit of time. It would be good to profile though to see if it can be optimized.

i think i have to scroll up down then new message came, i'll ask for a adhoc build (asked here )and test again to see if that makes a difference

This comment has been minimized.

@janicduplessis
Copy link
Contributor Author

@ishpaul777 Would you be able to confirm whether these bugs are also present on main? I think we could address them in a separate PR if so, as this one is already pretty big.

@ishpaul777
Copy link
Contributor

Not reproducable on main

Screen.Recording.2024-08-15.at.11.16.09.PM.mov

@ishpaul777
Copy link
Contributor

Not able to reproduce on with development build on simulator : \

Screen.Recording.2024-08-16.at.2.50.32.AM.mov

@ishpaul777
Copy link
Contributor

@janicduplessis
Copy link
Contributor Author

I am only able to reproduce on real device, will debug it today.

@janicduplessis
Copy link
Contributor Author

@ishpaul777 I am able to reproduce the issue when linking to first message on main too, I will have a quick look to see if it would be easy to fix, but I don't think it is a blocker to merge this.

@janicduplessis
Copy link
Contributor Author

janicduplessis commented Aug 16, 2024

Bug: after clicking "New messages" green button the last message got out of view quickly (chat scrolls a little up)

Bug: flickering after linking back to message from thread

@ishpaul777 I've been trying to repro the other 2 issues on both main and my branch and wasn't able to. Can you confirm whether it still happens for you?

@janicduplessis
Copy link
Contributor Author

I figured out the problem that causes the flickering. It is related to this patch https://github.com/janicduplessis/Expensify-App/blob/c91d1aac8ecbfbfce91b72bde1276aca74961e61/patches/react-native+0.73.4+016+iOSCoreAnimationBorderRendering.patch.

It calls [CATransaction commit] before the did mount observers run (where we adjust scroll position) which causes some intermediary state to be rendered.

@ishpaul777
Copy link
Contributor

@ishpaul777 I've been trying to repro the other 2 issues on both main and my branch and wasn't able to. Can you confirm whether it still happens for you?

Checking give me few minutes

Copy link
Contributor

@janicduplessis
Copy link
Contributor Author

I pushed the fix for the first issue. Note that the bug only happens on physical devices, a debug build works fine too, as long as it runs on physical device.

@janicduplessis
Copy link
Contributor Author

janicduplessis commented Aug 16, 2024

Updated description with the flicker fix

Fix flickering on iOS, this is caused by the patches/react-native+0.73.4+016+iOSCoreAnimationBorderRendering.patch patch which adds a CATransaction around mounting phase. This transaction should also include the willMount and didMount observer calls since we use those to adjust the scroll position and we don't want iOS to update the screen before those are called. This moves the CATransaction creation around the code that calls the observers.

@ishpaul777
Copy link
Contributor

ishpaul777 commented Aug 16, 2024

Bug: after clicking "New messages" green button the last message got out of view quickly (chat scrolls a little up)

Bug: flickering after linking back to message from thread

@ishpaul777 I've been trying to repro the other 2 issues on both main and my branch and wasn't able to. Can you confirm whether it still happens for you?

I am also not able to reproduce these on latest build 👍 Could be because of something wrong on main branch before

@janicduplessis
Copy link
Contributor Author

@ishpaul777 Anything missing on my side or is everything addressed now?

@ishpaul777
Copy link
Contributor

@ishpaul777 Anything missing on my side or is everything addressed now?

Addressed I was a bit occupied in other tasks now completing checklist

Copy link

melvin-bot bot commented Aug 16, 2024

We did not find an internal engineer to review this PR, trying to assign a random engineer to #46217 as well as to this PR... Please reach out for help on Slack if no one gets assigned!

@roryabraham roryabraham self-requested a review August 16, 2024 20:28
@roryabraham
Copy link
Contributor

discussing in slack here, but let's please be sure to go back and update this PR description with links to all the upstream commits and PRs for all the added patches

@roryabraham roryabraham merged commit 9cfe9c1 into Expensify:main Aug 19, 2024
17 checks passed
@janicduplessis janicduplessis deleted the @janic/fix-osr branch August 19, 2024 15:05
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/roryabraham in version: 9.0.22-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/roryabraham in version: 9.0.22-1 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/chiragsalian in version: 9.0.22-9 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants