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

[HOLD for payment 2023-10-02] [$1000] image loads on reesize window #26071

Closed
1 of 6 tasks
kavimuru opened this issue Aug 28, 2023 · 41 comments
Closed
1 of 6 tasks

[HOLD for payment 2023-10-02] [$1000] image loads on reesize window #26071

kavimuru opened this issue Aug 28, 2023 · 41 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@kavimuru
Copy link

kavimuru commented Aug 28, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. go to any chat
  2. send any image
  3. resize window

Expected Result:

should not show loader on resize window

Actual Result:

loader appears on resize window

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.57-2
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation

Screen.Recording.2023-08-18.at.11.47.50.AM.mov
Recording.2995.mp4

Expensify/Expensify Issue URL:
Issue reported by: @gadhiyamanan
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1692339507173639

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0123a04480c44d1baf
  • Upwork Job ID: 1696572921150214144
  • Last Price Increase: 2023-08-29
  • Automatic offers:
    • gadhiyamanan | Reporter | 26456730
@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 28, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 28, 2023

Triggered auto assignment to @puneetlath (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Aug 28, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@puneetlath
Copy link
Contributor

I don't understand. Why is the fact that it has to load when resizing a bug?

@tamdao
Copy link
Contributor

tamdao commented Aug 28, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

image loads on reesize window

What is the root cause of that problem?

This issue causes by CellRendererComponent of Flatlist

CellRendererComponent={renderCell}

const renderCell = useCallback(
(cellProps) => {
// Use window width instead of layout width to address the issue in https://github.com/Expensify/App/issues/17760
// considering horizontal margin and border width in centered modal
const modalStyles = styles.centeredModalStyles(isSmallScreenWidth, true);
const style = [cellProps.style, styles.h100, {width: PixelRatio.roundToNearestPixel(windowWidth - (modalStyles.marginHorizontal + modalStyles.borderWidth) * 2)}];
return (
<View
// eslint-disable-next-line react/jsx-props-no-spreading
{...cellProps}
style={style}
/>
);
},
[isSmallScreenWidth, windowWidth],
);

This function will mount and unmount the component when resize window. That mean call the renderItem function render the new item component, that why you see the loading state

const renderItem = useCallback(
({item}) => (
<AttachmentView
source={item.source}
file={item.file}
isAuthTokenRequired={item.isAuthTokenRequired}
isFocused={activeSource === item.source}
onPress={() => canUseTouchScreen && setShouldShowArrows(!shouldShowArrows)}
isUsedInCarousel
/>
),
[activeSource, setShouldShowArrows, shouldShowArrows],
);

and I also found another problem when user resize faster it will cause crash application and show something went wrong page.

This issue cause by withWindowDimensions function

useEffect(() => {
const onDimensionChange = (newDimensions) => {
const {window} = newDimensions;
setWindowDimension({
windowHeight: window.height,
windowWidth: window.width,
});
};
const dimensionsEventListener = Dimensions.addEventListener('change', onDimensionChange);
return () => {
if (!dimensionsEventListener) {
return;
}
dimensionsEventListener.remove();
};
}, []);

In this logic you are listener the dimension change event and this event will call when the dimension change and re-render component and cause the issue (Maximum update depth) when user re-size window multiple time.

What alternative solutions did you explore?

Fixed 1 Issue

Move this logic to out of the AttachmentCarousel component and use memo

const renderCell = useCallback(
(cellProps) => {
// Use window width instead of layout width to address the issue in https://github.com/Expensify/App/issues/17760
// considering horizontal margin and border width in centered modal
const modalStyles = styles.centeredModalStyles(isSmallScreenWidth, true);
const style = [cellProps.style, styles.h100, {width: PixelRatio.roundToNearestPixel(windowWidth - (modalStyles.marginHorizontal + modalStyles.borderWidth) * 2)}];
return (
<View
// eslint-disable-next-line react/jsx-props-no-spreading
{...cellProps}
style={style}
/>
);
},
[isSmallScreenWidth, windowWidth],
);

like this

const AttachmentCarouselCellRenderer = memo((props) => {
    const {windowWidth, isSmallScreenWidth} = useWindowDimensions();
    const modalStyles = styles.centeredModalStyles(isSmallScreenWidth, true);
    const style = [props.style, styles.h100, {width: PixelRatio.roundToNearestPixel(windowWidth - (modalStyles.marginHorizontal + modalStyles.borderWidth) * 2)}];

    return (
        <View
            // eslint-disable-next-line react/jsx-props-no-spreading
            {...props}
            style={style}
        />
    );
});

update the Flatlist line 215 to use new component

CellRendererComponent={AttachmentCarouselCellRenderer}

Fixed 2 Issue

Update the withWindowDimensions logic to use lodash debounce like this

const onDimensionChange = useCallback((newDimensions) => {
    const {window} = newDimensions;

    setWindowDimension({
        windowHeight: window.height,
        windowWidth: window.width,
    });
}, []);

const onDimensionChangeDebounce = useCallback(lodashDebounce(onDimensionChange, 300), []);

useEffect(() => {
    const dimensionsEventListener = Dimensions.addEventListener('change', onDimensionChangeDebounce);

    return () => {
        if (!dimensionsEventListener) {
            return;
        }
        dimensionsEventListener.remove();
    };
}, []);

I have tested and no longer see the crash issue.

@puneetlath
Copy link
Contributor

I don't think this is a bug as I mentioned here, so I'm going to go ahead and close. But feel free to comment if you disagree and we can keep discussing.

@tamdao
Copy link
Contributor

tamdao commented Aug 29, 2023

@puneetlath It's bug. You can take a look the code, it should only add style and not mount/unmount the component that mean kill the component and create new one. So, if you fix mount/unmount the component, the loading issue will be resolved because the image already loaded.

And another thing, because the logic mount/unmount the component it causes crash application like this

Screen.Recording.2023-08-29.at.07.25.04.mov

@puneetlath puneetlath reopened this Aug 29, 2023
@puneetlath
Copy link
Contributor

Ok interesting. How do you suggest we solve it?

@puneetlath puneetlath added the External Added to denote the issue can be worked on by a contributor label Aug 29, 2023
@melvin-bot melvin-bot bot changed the title image loads on reesize window [$1000] image loads on reesize window Aug 29, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

Job added to Upwork: https://www.upwork.com/jobs/~0123a04480c44d1baf

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 29, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

Current assignee @puneetlath is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @mananjadhav (External)

@saalimzafar

This comment was marked as off-topic.

@tamdao
Copy link
Contributor

tamdao commented Aug 30, 2023

@puneetlath @saalimzafar I found the root cause of the crash issue I mention above. This issue cause by withWindowDimensions function

useEffect(() => {
const onDimensionChange = (newDimensions) => {
const {window} = newDimensions;
setWindowDimension({
windowHeight: window.height,
windowWidth: window.width,
});
};
const dimensionsEventListener = Dimensions.addEventListener('change', onDimensionChange);
return () => {
if (!dimensionsEventListener) {
return;
}
dimensionsEventListener.remove();
};
}, []);

In this logic you are listener the dimension change event and this event will call when the dimension change and re-render component and cause the issue (Maximum update depth) when user re-size window multiple time.

@tamdao
Copy link
Contributor

tamdao commented Aug 30, 2023

@puneetlath @saalimzafar I have updated my proposal to fix 2 issue

Proposal

Updated

@pongzu313
Copy link

pongzu313 commented Aug 31, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

image loads on resize window

What is the root cause of that problem?

<AttachmentView
containerStyles={[styles.mh5]}
source={sourceForAttachmentView}
isAuthTokenRequired={isAuthTokenRequired}
file={file}
onToggleKeyboard={updateConfirmButtonVisibility}
isWorkspaceAvatar={props.isWorkspaceAvatar}
/>

The AttachmentView component re-renders when the AttachmentModal size changes.
After re-rendering the AttachmentImageView as above, re-rendering the ImageView.
When the ImageView re-renders, a loading spinner is displayed while loading the image with its URL.
const [isLoading, setIsLoading] = useState(true);

const imageLoadingStart = () => {
if (!isLoading) return;
setIsLoading(true);
setZoomScale(0);
setIsZoomed(false);
};
const imageLoad = ({nativeEvent}) => {
setImageRegion(nativeEvent.width, nativeEvent.height);
setIsLoading(false);
};

{isLoading && <FullscreenLoadingIndicator style={[styles.opacity1, styles.bgTransparent]} />}

So when window size changes, loading spinner in ImageView is displayed. This is the root cause of this problem.

What changes do you think we should make in order to solve the problem?

I think we should include a prop telling whether to show the loading spinner or not. To implement it, I change the ImageView to:

    function ImageView({isAuthTokenRequired, url, fileName, shouldDisplaySpinner})
    
    {isLoading && shouldDisplaySpinner && <FullscreenLoadingIndicator style={[styles.opacity1, styles.bgTransparent]} />}

@melvin-bot
Copy link

melvin-bot bot commented Aug 31, 2023

📣 @kanno927! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  2. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  3. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

@pongzu313
Copy link

Contributor details
Your Expensify account email: [email protected]
Upwork Profile Link: https://www.upwork.com/freelancers/~01edec99406e540586

@melvin-bot
Copy link

melvin-bot bot commented Aug 31, 2023

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

@mananjadhav
Copy link
Collaborator

Will review this today/tomorrow.

@mananjadhav
Copy link
Collaborator

@tamdao's proposal looks good. I am a bit concerned on debounce for withWindowsDimensions. I am wondering if this would cause any issue due to any incorrect dimenions.

@mananjadhav
Copy link
Collaborator

🎀 👀 🎀 C+ reviewed.

@melvin-bot
Copy link

melvin-bot bot commented Sep 1, 2023

Current assignee @puneetlath is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Daily KSv2 labels Sep 2, 2023
@tamdao
Copy link
Contributor

tamdao commented Sep 2, 2023

@mananjadhav @puneetlath PR is ready #26543. Please help me review it. Thanks ❤️

@melvin-bot
Copy link

melvin-bot bot commented Sep 21, 2023

Based on my calculations, the pull request did not get merged within 3 working days of assignment. Please, check out my computations here:

  • when @tamdao got assigned: 2023-09-01 18:17:08 Z
  • when the PR got merged: 2023-09-21 05:22:50 UTC
  • days elapsed: 13

On to the next one 🚀

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Sep 25, 2023
@melvin-bot melvin-bot bot changed the title [$1000] image loads on reesize window [HOLD for payment 2023-10-02] [$1000] image loads on reesize window Sep 25, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Sep 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.73-1 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2023-10-02. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

For reference, here are some details about the assignees on this issue:

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

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:

  • [@mananjadhav] The PR that introduced the bug has been identified. Link to the PR:
  • [@mananjadhav] 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:
  • [@mananjadhav] 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:
  • [@mananjadhav] Determine if we should create a regression test for this bug.
  • [@mananjadhav] 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.
  • [@puneetlath] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@puneetlath
Copy link
Contributor

@mananjadhav friendly reminder on the checklist so we can pay this out in a couple days. Thanks!

@puneetlath
Copy link
Contributor

@mananjadhav another friendly bump on the checklist so that we can pay.

@melvin-bot melvin-bot bot removed the Overdue label Oct 2, 2023
@gadhiyamanan
Copy link
Contributor

@puneetlath it is eligible for $250 for reporting bonus because it was logged before 30 Aug

Screenshot 2023-10-02 at 11 33 18 AM

@mananjadhav
Copy link
Collaborator

The change was introduced in this PR and I've added a comment here.

I don't think we need a regression test for this one. @puneetlath wdyt ? Also can you post the payout summary so that this can be paid out?

@puneetlath
Copy link
Contributor

Yes, I agree with you on that.

@puneetlath
Copy link
Contributor

puneetlath commented Oct 2, 2023

Payment summary:

$250 - @gadhiyamanan - bug report (paid via Upwork)
$1000 - @tamdao - contributor (paid via Upwork)
$1000 - @mananjadhav - C+ (to be paid via NewDot)

@tamdao please let me know when you've accepted the Upwork offer.
@mananjadhav let me know when you've created the request on NewDot.

Thanks everyone!

@tamdao
Copy link
Contributor

tamdao commented Oct 2, 2023

@puneetlath Accepted. Thanks

@puneetlath
Copy link
Contributor

Ok great. Just waiting for you to create a NewDot request @mananjadhav. Then we can close.

@mananjadhav
Copy link
Collaborator

@puneetlath I've created the request, we can close this one out.

@puneetlath
Copy link
Contributor

Great, thanks everyone!

@JmillsExpensify
Copy link

$1,000 payment approved for @mananjadhav based on BZ summary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

8 participants