Skip to content

[HOLD for payment 2024-01-26] [$500] Emoji - When resizing the window, the open emoji picker moves to the LHN side #31155

Closed

Description

@lanitochka17

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.3.97-0
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
Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

Action Performed:

  1. Open https://staging.new.expensify.com/
  2. Log in with any account
  3. Open any report
  4. In Compose Box, open the emoji picker
  5. Reduce the width of the open browser window

Expected Result:

Emoji picker should be fixed above the Compose Box when resizing the window and should remain open when going into mobile mode

Actual Result:

When resizing the window, the open emoji picker moves to the LHN side

Workaround:

Unknown

Platforms:

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

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6270312_1699554384569.Recording__692.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01b9e60337c2ef461a
  • Upwork Job ID: 1722692276888514560
  • Last Price Increase: 2023-11-30

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 9, 2023
  2. changed the title [-]Emoji - When resizing the window, the open emoji picker moves to the LHN side[/-] [+][$500] Emoji - When resizing the window, the open emoji picker moves to the LHN side[/+] on Nov 9, 2023
  3. melvin-bot commented on Nov 9, 2023

    @melvin-bot

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

  4. melvin-bot commented on Nov 9, 2023

    @melvin-bot
  5. melvin-bot commented on Nov 9, 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
  6. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Nov 9, 2023
  7. melvin-bot commented on Nov 9, 2023

    @melvin-bot

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

  8. jeet-dhandha commented on Nov 9, 2023

    @jeet-dhandha
    Contributor

    Proposal

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

    • Emoji picker sticking to left side of screen when we resize the window horizontally.

    What is the root cause of that problem?

    • In below code snippet the value comes as {horizontal: 0, vertical: 0} when we resize the window horizontally.

    calculateAnchorPosition(emojiPopoverAnchor.current, emojiPopoverAnchorOrigin).then((value) => {

    • This happens because when we copy reference of anchor element and then measure it's position using measureInWindow the response of callback comes as (x, y, width, height) => (0, 0, 0, 0) when we resize the window horizontally.

    • And if we check the original anchor element's position using measure it's position is correct.

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

    • First we create a useDimensionChange hook which will take a callback function and will call it whenever the dimension of the element changes.
    • then we move the calculate logic to a function onAnchorDimensionChange which takes the original ref and pass it to useImperativeHandle.

    const emojiPopoverDimensionListener = Dimensions.addEventListener('change', () => {
    if (!emojiPopoverAnchor.current) {
    // In small screen width, the window size change might be due to keyboard open/hide, we should avoid hide EmojiPicker in those cases
    if (isEmojiPickerVisible && !isSmallScreenWidth) {
    hideEmojiPicker();
    }
    return;
    }
    calculateAnchorPosition(emojiPopoverAnchor.current, emojiPopoverAnchorOrigin).then((value) => {
    setEmojiPopoverAnchorPosition(value);
    });
    });

    • then we create a onAnchorDimensionChange function in EmojiPickerAction.ts and call it in useDimensionChange at each place where we use the showEmojiPicker function.

    Below example is for EmojiPickerButton.js but we have to do the same for other places where we use showEmojiPicker function.

    // `emojiPopoverAnchor.current` is the original ref of the anchor element from `EmojiPickerButton.js`
    useDimensionChange(() => EmojiPickerAction.onAnchorDimensionChange(emojiPopoverAnchor.current));

    Video for EmojiPickerButton.js

    video
    c8046c9e-f613-4550-b13f-b300ef68a079.mp4

    What alternative solutions did you explore? (Optional)

    • N/A
  9. tienifr commented on Nov 10, 2023

    @tienifr
    Contributor

    Proposal

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

    When resizing the window, the open emoji picker moves to the LHN side

    What is the root cause of that problem?

    When we resize the window, the ref of the emoji button here will change, however, since we only passed the value (.current) of that ref here as the anchorRef, that anchorRef does not change and points to a non-existent component, leading to the dimensions become all 0 and the emoji picker moves to LHN side.

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

    The way we're passing refs as params to other components are not ideal, that way the original ref and the ref that we pass can get out of sync, causing issues like this one.

    So the pattern that we use is usually:

    • Create and update the ref inside the anchor component (in this case, inside EmojiPickerButton)
    • Pass that ref to another component that displays the actual popover (in this case, the EmojiPicker)
    1. We need to make sure they are always in sync, or ideally, always 1 single ref. We should create a new hook useSyncedRef that will return 1 ref for both components.
    import React from 'react';
    
    const refs = {}
    
    const useSyncedRef = (refKey, initialValue = undefined) => {
      if (!refs[refKey]) {
        refs[refKey] = React.createRef(initialValue);
      }
    
      const refCallback = (value) => {
        refs[refKey].current = value;
      }
    
      return { ref: refs[refKey], refCallback };
    }
    
    export default useSyncedRef;
    
    1. In EmojiPickerButton here
    const {refCallback} = useSyncedRef('EmojiPickerAnchor');
    

    And replace this
    with

    ref={refCallback}
    
    1. In EmojiPicker here, replace with
    const { ref: emojiPopoverAnchor } = useSyncedRef('EmojiPickerAnchor');
    

    And we don't need to pass the ref from the EmojiPickerButton to EmojiPicker via showEmojiPicker any more.

    What alternative solutions did you explore? (Optional)

    We can just add another method updateAnchorRef inside EmojiPicker and call it whenever the ref is updated in EmojiPickerButton

    Any place that has this issue can be fixed the same way by the main or alternative approach, but the main approach is global.

  10. bernhardoj commented on Nov 10, 2023

    @bernhardoj
    Contributor

    Proposal

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

    Resizing the browser window moves the emoji picker to the left side of the screen.

    What is the root cause of that problem?

    In EmojiPicker, we have a dimension change listener to calculate a new position.

    const emojiPopoverDimensionListener = Dimensions.addEventListener('change', () => {
    if (!emojiPopoverAnchor.current) {
    // In small screen width, the window size change might be due to keyboard open/hide, we should avoid hide EmojiPicker in those cases
    if (isEmojiPickerVisible && !isSmallScreenWidth) {
    hideEmojiPicker();
    }
    return;
    }
    calculateAnchorPosition(emojiPopoverAnchor.current, emojiPopoverAnchorOrigin).then((value) => {
    setEmojiPopoverAnchorPosition(value);
    });
    });

    The problem is, that the x, y, w, and h returned from calculateAnchorPosition is 0.

    This is because the element we want to measure (emojiPopoverAnchor.current) is not available on the dom anymore. emojiPopoverAnchor in this case is the emoji picker button.

    The element becomes not available as soon as the emoji picker menu shows. Why?

    The emoji picker button is wrapped with a PopoverAnchorTooltip.

    <Tooltip text={props.translate('reportActionCompose.emoji')}>
    <PressableWithoutFeedback
    ref={emojiPopoverAnchor}

    PopoverAnchorTooltip will conditionally render the element with/without a tooltip based on the popover visibility.

    if (!shouldRender || isPopoverRelatedToTooltipOpen) {
    return children;
    }
    return (
    <BaseTooltip
    // eslint-disable-next-line react/jsx-props-no-spreading
    {...props}
    tooltipRef={tooltipRef}
    >
    {children}
    </BaseTooltip>
    );

    When we first open the web, the emoji picker button is rendered with a tooltip, but when the emoji picker popover shows, we render the emoji picker button without a tooltip. This becomes a problem because if we render it with a tooltip, we clone the children (in this case the emoji picker button). So, both elements are different instances and the element that we pass to the EmojiPicker is the element of the with a tooltip.

    EmojiPickerAction.showEmojiPicker(props.onModalHide, props.onEmojiSelected, emojiPopoverAnchor.current, undefined, () => {}, props.emojiPickerID);

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

    Instead of passing the element as the emojiPopoverAnchorValue to EmojiPicker, we should pass the ref object so we can always get the latest value from the ref object.

    -EmojiPickerAction.showEmojiPicker(props.onModalHide, props.onEmojiSelected, emojiPopoverAnchor.current, undefined, () => {}, props.emojiPickerID);
    +EmojiPickerAction.showEmojiPicker(props.onModalHide, props.onEmojiSelected, emojiPopoverAnchor, undefined, () => {}, props.emojiPickerID);

    We should make the above changes to every usage of EmojiPickerAction.showEmojiPicker

    Then, we need to modify EmojiPicker so it works with the ref, that is by accessing the element by using double .current.

    if (emojiPopoverAnchor.current && emojiPopoverAnchor.current.blur) {
    // Drop focus to avoid blue focus ring.
    emojiPopoverAnchor.current.blur();
    }
    const anchorOriginValue = anchorOrigin || DEFAULT_ANCHOR_ORIGIN;
    calculateAnchorPosition(emojiPopoverAnchor.current, anchorOriginValue).then((value) => {

    if (!emojiPopoverAnchor.current) {
    // In small screen width, the window size change might be due to keyboard open/hide, we should avoid hide EmojiPicker in those cases
    if (isEmojiPickerVisible && !isSmallScreenWidth) {
    hideEmojiPicker();
    }
    return;
    }
    calculateAnchorPosition(emojiPopoverAnchor.current, emojiPopoverAnchorOrigin).then((value) => {

    emojiPopoverAnchor.current.current
    

    the first .current is to access the emojiPopoverAnchor ref object of EmojiPickerButton, and the second .current is to access the emojiPopoverAnchor element of EmojiPickerButton (the Pressable)

    Last, we need to modify below code so it pass the correct ref to the popover

    anchorRef={emojiPopoverAnchor}

    anchorRef={emojiPopoverAnchor.current ?? {}}
    
  11. 132 remaining items

  12. melvin-bot commented on Jan 19, 2024

    @melvin-bot

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

  13. melvin-bot commented on Jan 19, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.27-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 2024-01-26. 🎊

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

  14. melvin-bot commented on Jan 19, 2024

    @melvin-bot

    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:

    • [@aimane-chnaif] The PR that introduced the bug has been identified. Link to the PR:
    • [@aimane-chnaif] 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:
    • [@aimane-chnaif] 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:
    • [@aimane-chnaif] Determine if we should create a regression test for this bug.
    • [@aimane-chnaif] 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.
    • [@lschurr] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  15. changed the title [-][HOLD for payment 2024-01-26] [HOLD for payment 2024-01-04] [$500] Emoji - When resizing the window, the open emoji picker moves to the LHN side[/-] [+][HOLD for payment 2024-01-26] [$500] Emoji - When resizing the window, the open emoji picker moves to the LHN side[/+] on Jan 19, 2024
  16. lschurr commented on Jan 25, 2024

    @lschurr
    Contributor

    @aimane-chnaif - Can you work through the checklist on this one?

  17. aimane-chnaif commented on Jan 25, 2024

    @aimane-chnaif
    Contributor
    • The PR that introduced the bug has been identified. Link to the PR: Add popover anchor tooltip #30150
    • 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: https://github.com/Expensify/App/pull/30150/files#r1439823954
    • 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: N/A
    • Determine if we should create a regression test for this bug. This is kind of edge case and caught by QA team so no need regression test
    • 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.
  18. lschurr commented on Jan 29, 2024

    @lschurr
    Contributor

    It looks like the automation didn't work here. Moving to Daily and will handle payments shortly.

  19. added and removed on Jan 29, 2024
  20. lschurr commented on Jan 30, 2024

    @lschurr
    Contributor

    Payment summary:

  21. lschurr commented on Jan 30, 2024

    @lschurr
    Contributor

    Offers sent in Upwork.

  22. aimane-chnaif commented on Jan 30, 2024

    @aimane-chnaif
    Contributor

    Offer accepted already - #31155 (comment)

  23. lschurr commented on Jan 30, 2024

    @lschurr
    Contributor

    Ah, sorry about that! I'll use the previous offers.

  24. lschurr commented on Jan 30, 2024

    @lschurr
    Contributor

    Payments issued. Closing this one out.

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.DailyKSv2EngineeringInternalRequires API changes or must be handled by Expensify staff

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions