Skip to content

[Refactor] Extract a shared helper for dynamic-route path joining (root-base slash normalization) #98145

Description

@MelvinBot

Problem

The logic that joins a dynamic-route base path with its suffix — special-casing a root base (/) so the two aren't concatenated into a //-prefixed (protocol-relative) path — is duplicated in several places in the navigation layer:

Each site independently does base === '/' ? \/${suffix}` : `${base}/${suffix}`. Because this same rule lives in multiple places, it's easy for one copy to drift or be forgotten — which is exactly what caused the SecurityError: Failed to execute 'pushState'crash fixed in Expensify/App#97849 (thegetPathFromStatecopy was missing the root-base guard and produced//ai-features-promo`).

Proposed change

Extract a small shared helper (e.g. joinPathSegments(base, suffix)) that returns the correctly-adjusted path, and use it at every site above so the slash-normalization rule is defined once.

Note

This came out of a NAB review comment on the fix PR: #97849 (comment)

NAB: Maybe we can extract a helper to return an adjusted path. I see that this logic is repeated elsewhere in the code

Follow-up to #97849.

Issue OwnerCurrent Issue Owner: @collectioneur

Activity

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions