You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Pay 7/30] [Dev] - [StrictMode] Attachments not loading and app crashes when click on loading preview from attachment #44566
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Please re-state the problem that we are trying to solve in this issue.
Attachment is infinitely loading and crash when opens in DEV.
What is the root cause of that problem?
This happens because of the new strict mode. For the crash, it happens becuase of maximum update stack error. As we know, strict mode will cause the component to mount and unmounted twice. What happen is, the modal is open and close repeatedly and infinitely. The attachment carousel has an effect that calls onNavigate when the valid attachment is found on the report
// This enables Composer refocus when the attachments modal is closed by the browser navigation
ComposerFocusManager.setReadyToFocus();
}}
For the infinite loading issue, it comes from the react-native-web image headers patch that we have. The image header has 2 useEffects.
The first one is to cancel any ongoing request and remade a new one when the source is updated, and the others to cancel any ongoing request when unmounted.
But because of the strict mode, the unmounted cleanup is called, which cancels the ongoing request. The 1st useEffect won't do the setup anymore on the 2nd call/run because the source hasn't been updated yet (the current source and the prop source is still the same), so the request is never remade.
What changes do you think we should make in order to solve the problem?
To fix the crash, we should replace onModalHide with onModalClose.
// This enables Composer refocus when the attachments modal is closed by the browser navigation
ComposerFocusManager.setReadyToFocus();
}}
Why? I think in this case, doing a navigation isn't supposed to be done in a useEffect and rather should be done when the user takes the action to do so, like when a user buy an item from a button click, not from an effect.
onModalClose is called whenever the user takes the action to close the modal, either by pressing ESC, back button, backdrop/overlay press, swipe to bottom, shortcut to open other pages, etc. (we use onModalClose for other attachment page, WorkspaceAvatar, ProfileAvatar, ReportAvatar, & TransactionReceiptPage).
If we want to keep using onModalHide, then we can introduce a new ref in AttachmentModal that turns true whenever closeModal is called (called by user action), then we pass it to the onModalHide params. If it's true, then we do the navigation.
For the infinite loading issue, another reason the strict mode exist is to make sure we setup and cleanup an effect properly. In the image with headers case, it's a bit different. In a normal case, we would do something like this:
However, the deps of image with headers includes onLoadStart, onError, onLoadEnd and looks like we don't want the request to be cancelled and remade when those changes. We can remove them from the effect deps, but the source prop is an object which is unstable, thus we made a comparison using hasSourceDiff,
and only cancel and remade the request when the source content (uri and headers) is really updated.
So, to fix this, I propose to clears the current request source when the component is unmounted.
// Cancel any request on unmount
React.useEffect(() => () => {
request.current.cancel();
// reset to the init value of request, we can move the initial value to a variable
request.current = {
cancel: () => {},
source: {
uri: '',
headers: {}
},
promise: Promise.resolve('')
}
}, []);
The above code clears the current request with the initial request value, but I think it's better if the initial request value is null to make it simple. Then, we just need to adjust the code here to add null safety to the current request source and default it to an empty object.
If you see the 2nd link above, you will notice that the image (without headers) will cancel and remade the request whenever onLoadStart, onError, onLoadEnd is updated, if we want to do that with image with headers too, then we can update the current useEffect structure to be like in the snippet example I gave above.
But, I'm not sure how should we approach this rn-web patch fix. The upstream PR for this patch hasn't been closed yet and currently is merged to the rn-web 0.20 preview PR.
@ikevin127 plz complete the BZ checklist below. thx
BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:
[@] The PR that introduced the bug has been identified. Link to the PR:
[@] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
[@] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
[@] Determine if we should create a regression test for this bug.
[@] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
[@bz] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
[@ikevin127] Determine if we should create a regression test for this bug.
[@ikevin127] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
Regression Test Proposal
Send an image attachment to a chat.
While the attachment is still loading (uploading), click on the loading attachment preview to open it.
On the attachment page, if the image is still loading (uploading) -> verify that the loading indicator is displayed and the app doesn't crash.
On the attachment page, once the image was uploaded, verify that the image is displayed and the app doesn't crash.
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Activity
melvin-bot commentedon Jun 27, 2024
Triggered auto assignment to @mallenexpensify (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.MelvinBot commentedon Jun 27, 2024
This has been labelled "Needs Reproduction". Follow the steps here: https://stackoverflowteams.com/c/expensify/questions/16989
mallenexpensify commentedon Jun 28, 2024
Can't remember the best practice for dev issues so checking on in #bug-zero
https://expensify.slack.com/archives/C01SKUP7QR0/p1719540502698309
bernhardoj commentedon Jul 1, 2024
Proposal
Please re-state the problem that we are trying to solve in this issue.
Attachment is infinitely loading and crash when opens in DEV.
What is the root cause of that problem?
This happens because of the new strict mode. For the crash, it happens becuase of maximum update stack error. As we know, strict mode will cause the component to mount and unmounted twice. What happen is, the modal is open and close repeatedly and infinitely. The attachment carousel has an effect that calls
onNavigatewhen the valid attachment is found on the reportApp/src/components/Attachments/AttachmentCarousel/index.tsx
Lines 89 to 92 in d489ba4
onNavigatewill call this function to update the route.App/src/pages/home/report/ReportAttachments.tsx
Lines 25 to 31 in d489ba4
But the modal component has a cleanup effect that will calls
onModalHide.App/src/components/Modal/BaseModal.tsx
Lines 113 to 123 in d489ba4
And
onModalHidewill close the attachment carousel page in this case.App/src/pages/home/report/ReportAttachments.tsx
Lines 41 to 45 in d489ba4
For the infinite loading issue, it comes from the react-native-web image headers patch that we have. The image header has 2
useEffects.The first one is to cancel any ongoing request and remade a new one when the source is updated, and the others to cancel any ongoing request when unmounted.
App/patches/react-native-web+0.19.12+003+image-header-support.patch
Lines 78 to 99 in d489ba4
But because of the strict mode, the unmounted cleanup is called, which cancels the ongoing request. The 1st
useEffectwon't do the setup anymore on the 2nd call/run because the source hasn't been updated yet (the current source and the prop source is still the same), so the request is never remade.What changes do you think we should make in order to solve the problem?
To fix the crash, we should replace
onModalHidewithonModalClose.App/src/pages/home/report/ReportAttachments.tsx
Lines 41 to 45 in d489ba4
Why? I think in this case, doing a navigation isn't supposed to be done in a
useEffectand rather should be done when the user takes the action to do so, like when a user buy an item from a button click, not from an effect.onModalCloseis called whenever the user takes the action to close the modal, either by pressing ESC, back button, backdrop/overlay press, swipe to bottom, shortcut to open other pages, etc. (we use onModalClose for other attachment page, WorkspaceAvatar, ProfileAvatar, ReportAvatar, & TransactionReceiptPage).If we want to keep using
onModalHide, then we can introduce a new ref inAttachmentModalthat turns true whenevercloseModalis called (called by user action), then we pass it to theonModalHideparams. If it's true, then we do the navigation.For the infinite loading issue, another reason the strict mode exist is to make sure we setup and cleanup an effect properly. In the image with headers case, it's a bit different. In a normal case, we would do something like this:
However, the deps of image with headers includes
onLoadStart, onError, onLoadEndand looks like we don't want the request to be cancelled and remade when those changes. We can remove them from the effect deps, but thesourceprop is an object which is unstable, thus we made a comparison usinghasSourceDiff,App/patches/react-native-web+0.19.12+003+image-header-support.patch
Lines 22 to 24 in d489ba4
and only cancel and remade the request when the source content (uri and headers) is really updated.
So, to fix this, I propose to clears the current request source when the component is unmounted.
The above code clears the current request with the initial request value, but I think it's better if the initial request value is null to make it simple. Then, we just need to adjust the code here to add null safety to the current request source and default it to an empty object.
App/patches/react-native-web+0.19.12+003+image-header-support.patch
Line 79 in d489ba4
Resetting it to null is similar to what the rn-web did with the image (without headers).
initial value is null: https://github.com/necolas/react-native-web/blob/54c14d64dabd175e8055e1dc92e9196c821f9b7d/packages/react-native-web/src/exports/Image/index.js#L218
resets to null: https://github.com/necolas/react-native-web/blob/54c14d64dabd175e8055e1dc92e9196c821f9b7d/packages/react-native-web/src/exports/Image/index.js#L312-L320
If you see the 2nd link above, you will notice that the image (without headers) will cancel and remade the request whenever
onLoadStart, onError, onLoadEndis updated, if we want to do that with image with headers too, then we can update the currentuseEffectstructure to be like in the snippet example I gave above.But, I'm not sure how should we approach this rn-web patch fix. The upstream PR for this patch hasn't been closed yet and currently is merged to the rn-web 0.20 preview PR.
melvin-bot commentedon Jul 1, 2024
@mallenexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
melvin-bot commentedon Jul 2, 2024
Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.
melvin-bot commentedon Jul 2, 2024
Triggered auto assignment to Contributor-plus team member for initial proposal review - @alitoshmatov (
External)37 remaining items
ikevin127 commentedon Jul 31, 2024
cc @mallenexpensify
mallenexpensify commentedon Jul 31, 2024
Contributor: @bernhardoj owed $250 via Upwork
Contributor+: @ikevin127 paid $250 via Upwork.
@ikevin127 can you please accept the job and reply here once you have?
https://www.upwork.com/jobs/~01650c8361cab58c60
@ikevin127 plz complete the BZ checklist below. thx
BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:
mallenexpensify commentedon Jul 31, 2024
@ikevin127 paid, post above updated to reflect payment.
ikevin127 commentedon Jul 31, 2024
Regression Test Proposal
Do we agree 👍 or 👎.
bernhardoj commentedon Aug 1, 2024
Requested in ND.
JmillsExpensify commentedon Aug 1, 2024
$250 approved for @bernhardoj
mallenexpensify commentedon Aug 6, 2024
Test Case GH