Skip to content

[HOLD for payment 2024-08-09] [$250] Switch to expensify classic button not working on m-web safari #45941

Closed

Description

@m-natarajan

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: 9.0.10-6
Reproducible in staging?: Yes
Reproducible in production?: Yes
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: @ishpaul777
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1721668187994169

Action Performed:

  1. Go to https://staging.new.expensify.com/settings/exit-survey/reason on mweb
  2. Complete the flow
  3. Click green Switch to Expensify Classic button

Expected Result:

User is redirected to olddot

Actual Result:

User is not redirected to olddot and button nonfunctional

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

Screen.Recording.2024-07-22.at.8.51.47.PM.mov
RPReplay_Final1721677493.MP4

Add any screenshot/video evidence

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01550410ab679e7457
  • Upwork Job ID: 1815808508017223645
  • Last Price Increase: 2024-07-23
  • Automatic offers:
    • akinwale | Reviewer | 103303782
Issue OwnerCurrent Issue Owner: @abekkala

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jul 22, 2024
  2. melvin-bot commented on Jul 22, 2024

    @melvin-bot

    Triggered auto assignment to @abekkala (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.

  3. nyomanjyotisa commented on Jul 23, 2024

    @nyomanjyotisa
    Member

    Proposal

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

    Switch to expensify classic button not working on m-web safari

    What is the root cause of that problem?

    The root cause of the issue is that the Linking.openURL method in React Native is not handling the URL correctly on Safari. Specifically, Safari has stricter URL handling requirements, and URLs need to be properly encoded to ensure they are opened correctly.

    const asyncOpenURL: AsyncOpenURL = (promise, url) => {
    if (!url) {
    return;
    }
    promise.then((params) => {
    Linking.openURL(typeof url === 'string' ? url : url(params));
    });
    };

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

    To address the issue, the following changes are proposed:

    • Ensure that the URL passed to Linking.openURL is properly encoded. This prevents any special characters in the URL from causing issues in Safari.
    • Modify the asyncOpenURL function to encode the URL before opening it with Linking.openURL

    Update this code to the following

        promise.then((params) => {
            const finalURL = typeof url === 'string' ? url : url(params);
            const encodedURL = encodeURIComponent(finalURL);
            Linking.openURL(encodedURL);
        });
    

    RESULT

    Switch-to-expensify-classic-button-not-working-on-m-web-safari-.-Issue-45941-.-Expensify-App.mp4

    What alternative solutions did you explore? (Optional)

  4. bernhardoj commented on Jul 23, 2024

    @bernhardoj
    Contributor

    Proposal

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

    Switch to expensify classic doesn't work in mWeb Safari.

    What is the root cause of that problem?

    Pressing the switch to expensify classic button will do an API request and will try to open the old dot link after the promise is resolved.

    onPress={() => {
    ExitSurvey.switchToOldDot().then(() => {
    if (NativeModules.HybridAppModule) {
    Navigation.resetToHome();
    NativeModules.HybridAppModule.closeReactNativeApp();
    return;
    }
    Link.openOldDotLink(CONST.OLDDOT_URLS.INBOX);
    });

    However, opening a link/new tab inside a promise doesn't work on mWeb Safari. We previously had this kind of issue at #3615 which we fix it by opening a new window first then wait for the promise to complete.

    const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
    if (!isSafari || shouldSkipCustomSafariLogic) {
    promise.then((params) => {
    Linking.openURL(typeof url === 'string' ? url : url(params));
    });
    } else {
    const windowRef = window.open();
    promise
    .then((params) => {
    if (!windowRef) {
    return;
    }
    windowRef.location = typeof url === 'string' ? url : url(params);
    })
    .catch(() => windowRef?.close());

    The issue is that in mWeb Safari, opening a new tab/link requires a user gesture, and putting it inside a promise won't be considered a user gesture anymore.

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

    Call Link.openOldDotLink(CONST.OLDDOT_URLS.INBOX); outside of the promise (we can do it only for mWeb Safari).

    onPress={() => {
    ExitSurvey.switchToOldDot().then(() => {
    if (NativeModules.HybridAppModule) {
    Navigation.resetToHome();
    NativeModules.HybridAppModule.closeReactNativeApp();
    return;
    }
    Link.openOldDotLink(CONST.OLDDOT_URLS.INBOX);
    });

    if (!NativeModules.HybridAppModule) {
        Link.openOldDotLink(CONST.OLDDOT_URLS.INBOX);
    }
    

    If we only do it in safari, then pressing the Switch to expensify classic will immediately open the new window, while for other platforms, we will wait until the loading is complete.

    What alternative solutions did you explore? (Optional)

    The main solution will open the window and set the old link link as the url to the window without waiting the switchToOldDot request to complete. If we want to wait for switchToOldDot, then we can update openOldDotLink to accept a new params called extraPromise. We pass the switchToOldDot to the extraPromise and wait for it to complete.

    if (!NativeModules.HybridAppModule) {
        Link.openOldDotLink(CONST.OLDDOT_URLS.INBOX, ExitSurvey.switchToOldDot());
    } else {
        ExitSurvey.switchToOldDot().then(() => {
            Navigation.resetToHome();
            NativeModules.HybridAppModule.closeReactNativeApp();
        });
    }
    

    // If shortLivedAuthToken is not accessible, fallback to opening the link without the token.
    asyncOpenURL(
    // eslint-disable-next-line rulesdir/no-api-side-effects-method
    API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.OPEN_OLD_DOT_LINK, {}, {})
    .then((response) => (response ? buildOldDotURL(url, response.shortLivedAuthToken) : buildOldDotURL(url)))
    .catch(() => buildOldDotURL(url)),
    (oldDotURL) => oldDotURL,
    );

    extraPromise.then(() => 
        API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.OPEN_OLD_DOT_LINK, {}, {})
            .then((response) => (response ? buildOldDotURL(url, response.shortLivedAuthToken) : buildOldDotURL(url)))
            .catch(() => buildOldDotURL(url))
    ),
    
  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jul 23, 2024
  6. melvin-bot commented on Jul 23, 2024

    @melvin-bot
  7. changed the title [-]Switch to expensify classic button not working on m-web safari[/-] [+][$250] Switch to expensify classic button not working on m-web safari[/+] on Jul 23, 2024
  8. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jul 23, 2024
  9. melvin-bot commented on Jul 23, 2024

    @melvin-bot

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

  10. akinwale commented on Jul 26, 2024

    @akinwale
    Contributor

    After reviewing both proposals, we can move forward with @bernhardoj's proposal here since the solution follows a pattern that already exists in the codebase.

    🎀👀🎀 C+ reviewed.

  11. melvin-bot commented on Jul 26, 2024

    @melvin-bot

    Triggered auto assignment to @srikarparsi, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

  12. 13 remaining items

  13. changed the title [-][$250] Switch to expensify classic button not working on m-web safari[/-] [+][HOLD for payment 2024-08-09] [$250] Switch to expensify classic button not working on m-web safari[/+] on Aug 2, 2024
  14. melvin-bot commented on Aug 2, 2024

    @melvin-bot

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

  15. melvin-bot commented on Aug 2, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.15-9 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-08-09. 🎊

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

  16. melvin-bot commented on Aug 2, 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:

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

    @abekkala
    Contributor

    PAYMENT SUMMARY FOR AUG 09, if no regressions

  18. akinwale commented on Aug 3, 2024

    @akinwale
    Contributor
    • [@akinwale] The PR that introduced the bug has been identified. Link to the PR:
    • [@akinwale] 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:
    • [@akinwale] 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:

    Not a regression.

    • [@akinwale] Determine if we should create a regression test for this bug.
    • [@akinwale] 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 Steps

    1. Launch Expensify on Safari on iOS
    2. Navigate to Settings then select Switch to Expensify Classic
    3. Complete the survey
    4. Tap the Switch to Expensify Classic button
    5. Verify that a new tab opens and loads the Old Dot URL

    Do we agree 👍 or 👎?

  19. bernhardoj commented on Aug 9, 2024

    @bernhardoj
    Contributor

    Requested in ND.

  20. abekkala commented on Aug 9, 2024

    @abekkala
    Contributor

    @akinwale payment sent and contract ended - thank you! 🎉

    Thank you @bernhardoj

    Closing

  21. JmillsExpensify commented on Aug 9, 2024

    @JmillsExpensify
    Contributor

    $250 approved for @bernhardoj

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