Skip to content

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

Closed

Description

@kavimuru

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com 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

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Aug 28, 2023
  2. melvin-bot commented on Aug 28, 2023

    @melvin-bot

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

  3. melvin-bot commented on Aug 28, 2023

    @melvin-bot

    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
  4. puneetlath commented on Aug 28, 2023

    @puneetlath
    Contributor

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

  5. tamdao commented on Aug 28, 2023

    @tamdao
    Contributor

    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.

  6. puneetlath commented on Aug 28, 2023

    @puneetlath
    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.

  7. tamdao commented on Aug 29, 2023

    @tamdao
    Contributor

    @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
  8. puneetlath commented on Aug 29, 2023

    @puneetlath
    Contributor

    Ok interesting. How do you suggest we solve it?

  9. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Aug 29, 2023
  10. changed the title [-] image loads on reesize window[/-] [+][$1000] image loads on reesize window[/+] on Aug 29, 2023
  11. melvin-bot commented on Aug 29, 2023

    @melvin-bot
  12. 36 remaining items

  13. puneetlath commented on Oct 2, 2023

    @puneetlath
    Contributor

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

  14. gadhiyamanan commented on Oct 2, 2023

    @gadhiyamanan
    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

  15. mananjadhav commented on Oct 2, 2023

    @mananjadhav
    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?

  16. puneetlath commented on Oct 2, 2023

    @puneetlath
    Contributor

    Yes, I agree with you on that.

  17. puneetlath commented on Oct 2, 2023

    @puneetlath
    Contributor

    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!

  18. tamdao commented on Oct 2, 2023

    @tamdao
    Contributor

    @puneetlath Accepted. Thanks

  19. puneetlath commented on Oct 3, 2023

    @puneetlath
    Contributor

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

  20. mananjadhav commented on Oct 4, 2023

    @mananjadhav
    Collaborator

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

  21. puneetlath commented on Oct 5, 2023

    @puneetlath
    Contributor

    Great, thanks everyone!

  22. JmillsExpensify commented on Oct 5, 2023

    @JmillsExpensify
    Contributor

    $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

Metadata

Metadata

Labels

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

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions