Skip to content

Implement query parameters handling in dynamic routes#84158

Merged
mjasikowski merged 13 commits intoExpensify:mainfrom
software-mansion-labs:collectioneur/dynamic-routes-parameters-handling
Mar 12, 2026
Merged

Implement query parameters handling in dynamic routes#84158
mjasikowski merged 13 commits intoExpensify:mainfrom
software-mansion-labs:collectioneur/dynamic-routes-parameters-handling

Conversation

@collectioneur
Copy link
Contributor

@collectioneur collectioneur commented Mar 4, 2026

Explanation of Change

Add query parameter support to dynamic routes. Previously, dynamic suffixes couldn't include query params (e.g., country?country=US). This extends DynamicRouteConfig with an optional getRoute function, refactors createDynamicRoute to merge base and suffix query strings, and updates getPathWithoutDynamicSuffix to strip suffix-specific params. Migrates SETTINGS_ADDRESS_COUNTRY from a static route to the new ADDRESS_COUNTRY dynamic route as a proof of concept.

Fixed Issues

$ #84119

Tests

  • Verify that no errors appear in the JS console

1 test

  1. Navigate to Settings > Profile > Address
  2. Tap on the Country field to open the country selection page
  3. Select a different country (e.g., "United States")
  4. Verify that you are navigated back to the Address page with the selected country populated correctly
  5. Tap on the Country field again and verify the previously selected country is shown as the current selection

2 test

  1. Navigate to Settings > Profile > Address
  2. Tap on the Country field to open the country selection page
  3. Press the back button (header back arrow) without selecting a new country
  4. Verify that you return to the Address page and the original country value is preserved

3 test

  1. Open the app and navigate directly to a deep link like settings/profile/address/country?country=US
  2. Verify the country selection page opens with "US" pre-selected
  3. Select a different country and verify navigation back to the address page works correctly

Test 4

  1. Navigate to Settings -> Wallet -> Add Bank Account and log into the US bank account (log into the fake Plaid using the staging server).
  2. While on the address step, open the country page.
  3. Verify that the country suffix, along with the country parameter, is added to the URL.
  4. Refresh the page and verify that the screen underneath the RHP is still the settings/wallet.

Offline tests

N/A

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
Screen.Recording.2026-03-06.at.17.22.34.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-03-06.at.16.51.33.mov

add-us-bank-account test country page:
https://github.com/user-attachments/assets/39923dfb-4636-4c20-a96d-878508f6f617

…ponents, and updating navigation dynamic routes logic.
@codecov
Copy link

codecov bot commented Mar 6, 2026

@collectioneur collectioneur changed the title Collectioneur/dynamic routes parameters handling Implement parameters handling in dynamic routes Mar 6, 2026
@collectioneur collectioneur force-pushed the collectioneur/dynamic-routes-parameters-handling branch from 39a53ba to a55b125 Compare March 6, 2026 14:02
Comment on lines +7 to +10
/**
* Merges two query strings into one. If both contain the same key,
* the suffix value wins and a warning is logged.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an example in the docs? What will be the result of merging two example values etc.

import splitPathAndQuery from './splitPathAndQuery';

function getQueryParamsToStrip(dynamicSuffix: string): readonly string[] | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a description to this function

@WojtekBoman
Copy link
Contributor

WojtekBoman commented Mar 9, 2026

I see we have a lot of functions related to dynamic routes which are kept directly in Navigation/helpers, maybe it would be a good idea to create something like DynamicRoutesUtils to store them together, thanks to that it will be easy to recognize if the function is connected to the logic of dynamic routes

@collectioneur collectioneur changed the title Implement parameters handling in dynamic routes Implement query parameters handling in dynamic routes Mar 10, 2026
…dynamic routes and dynamic routes with query parameters
@collectioneur collectioneur marked this pull request as ready for review March 10, 2026 17:51
@collectioneur collectioneur requested review from a team as code owners March 10, 2026 17:51
@melvin-bot melvin-bot bot requested review from huult and removed request for a team March 10, 2026 17:51
@melvin-bot
Copy link

melvin-bot bot commented Mar 10, 2026

@huult Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot requested review from joekaufmanexpensify and removed request for a team March 10, 2026 17:51
@joekaufmanexpensify
Copy link
Contributor

No product review needed

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@huult
Copy link
Contributor

huult commented Mar 11, 2026

Screen.Recording.2026-03-11.at.15.03.59.mov

BUG:

  1. Go to Settings -> Profile -> Address -> Country
  2. Reload the page
  3. Select any country
  4. Observe the URL: the suffix is removed before the query parameter is removed. As a result, the query parameter still exists briefly before it is removed.

This issue does not occur if the page is not reloaded.

@huult
Copy link
Contributor

huult commented Mar 11, 2026

Screen.Recording.2026-03-11.at.15.15.41.mov

BUG:

  1. Go to Settings -> Profile -> Address -> Country
  2. Manually remove the country code so the URL becomes /settings/profile/address?country=
  3. Reload the page
  4. Navigate back and open the Country screen again

@huult
Copy link
Contributor

huult commented Mar 11, 2026

@collectioneur Could you add the test steps and record the case when adding a bank account at the address step? This is because the CountrySelector is used there.

Screen.Recording.2026-03-11.at.15.36.56.mov

@huult
Copy link
Contributor

huult commented Mar 11, 2026

Screen.Recording.2026-03-11.at.15.42.42.mov

BUG:

  1. Go to Settings -> Wallet -> Add Bank Account
  2. Log in with the account: user_good
  3. Enter the required information and proceed to the Address step
  4. Navigate to Country Selection and reload the page
  5. The page is redirected to the Workspace Chat. It should remain on the current page (Wallet).

@collectioneur
Copy link
Contributor Author

collectioneur commented Mar 11, 2026

Go to Settings -> Profile -> Address -> Country
Reload the page
Select any country
Observe the URL: the suffix is removed before the query parameter is removed. As a result, the query parameter still exists briefly before it is removed.

@huult This behavior is specific to the page I just migrated. Here's what's happening: to pass the data about a selected or existing parameter back, it has to attach this parameter to the previous page and then navigate back. This allows the previous page to properly extract the parameter and clean it up from the URL.
Normally, without a refresh, you don't even notice this because it happens instantly. However, if you refresh and then navigate back, the page re-renders and gets pushed to the navigation state. That's why you can see the parameter attached to the previous page for those few milliseconds.
So, this isn't a dynamic routes bug, it's just the specific behavior of this particular page. As for the other bugs, they have all been resolved 😄:

Screen.Recording.2026-03-11.at.16.36.37.mov
Screen.Recording.2026-03-11.at.16.37.20.mov

@collectioneur
Copy link
Contributor Author

collectioneur commented Mar 11, 2026

@collectioneur Could you add the test steps and record the case when adding a bank account at the address step? This is because the CountrySelector is used there.

Added test and recorded the case. Could you please give it one more review when you have a chance 🙂 ? Thank you!

@huult
Copy link
Contributor

huult commented Mar 12, 2026

Reviewer Checklist

@huult
Copy link
Contributor

huult commented Mar 12, 2026

@codex review

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copy link
Contributor

@huult huult left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@melvin-bot melvin-bot bot requested a review from mjasikowski March 12, 2026 05:28
@mjasikowski
Copy link
Contributor

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

We were unable to download your code in a timely manner.
ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@mjasikowski
Copy link
Contributor

One more try
@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 70807267fa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

!isNavigatingToAttachmentScreen(focusedRouteFromPath?.name) &&
!isNavigatingToReportWithSameReportID(currentFocusedRoute, focusedRouteFromPath)
!isNavigatingToReportWithSameReportID(currentFocusedRoute, focusedRouteFromPath) &&
!findMatchingDynamicSuffix(normalizedPath)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Limit dynamic-route detection before skipping PUSH conversion

This new guard uses findMatchingDynamicSuffix(normalizedPath) to decide whether to keep NAVIGATE, but that suffix check is purely textual and also matches non-dynamic routes that end in the same segment (for example static .../verify-account routes such as SETTINGS_2FA_VERIFY_ACCOUNT and SETTINGS_WALLET_TRAVEL_CVV_VERIFY_ACCOUNT in src/ROUTES.ts). In those cases this branch now stops converting NAVIGATE to PUSH, which can reuse an existing stack entry and skip adding a history entry, regressing back/navigation behavior for normal static screens.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the context of the screens (RHPs) we are currently migrating, there is no scenario where they would have been in the navigation stack previously. Because of this, it is perfectly safe to leave the logic as it is. If any unforeseen regressions arise in the future, we can easily revisit and update this behavior

Copy link
Contributor

@mjasikowski mjasikowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

@mjasikowski mjasikowski merged commit 03d6c3f into Expensify:main Mar 12, 2026
38 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions
Copy link
Contributor

🚧 @mjasikowski has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mjasikowski in version: 9.3.37-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@nkuoch
Copy link
Contributor

nkuoch commented Mar 13, 2026

@collectioneur @mjasikowski this likely caused #85191 (comment). Should we revert? Not sure, as I feel the bug (landing on the settings page after adding the PBA instead of staying on the expense details page) is not a huge deal, and could maybe just be a follow up

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/cristipaval in version: 9.3.37-10 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants