Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sanitizedUrl.search to format search params #338

Merged
merged 1 commit into from
Nov 24, 2021
Merged

Use sanitizedUrl.search to format search params #338

merged 1 commit into from
Nov 24, 2021

Conversation

garand
Copy link
Contributor

@garand garand commented Nov 11, 2021

I was running into an issue with this while setting up a Vite frontend (React template) with the SWA cli.

The change of adding matchingRewriteRouteQueryString to the end results in this:

[swa] /src/logo.svgimport=

Notice the missing ? prefix.

I instead replaced it with this:

if (doesMatchingRewriteRouteHaveQueryStringParameters) {
-    matchingRewriteRoutePath = sanitizedUrl.pathname + matchingRewriteRouteQueryString; // => /src/logo.svgimport=
+    matchingRewriteRoutePath = sanitizedUrl.pathname + sanitizedUrl.search;  // => /src/logo.svg?import
    core_1.logger.silly(` - query: ${chalk_1.default.yellow(matchingRewriteRouteQueryString)}`);
}

The mapping is now correct.

[swa] /src/logo.svg?import

And it correctly appends the search params and lets the Vite React starter load correctly.

Replaces `matchingRewriteRouteQueryString` with `sanitizedUrl.search` to property format the search params
@garand garand changed the title fix: use sanitizedUrl.search to format search params Use sanitizedUrl.search to format search params Nov 11, 2021
@github-actions github-actions bot added the scope: rules engine Specific issues related to src/msha/routes-engine/** label Nov 11, 2021
Copy link
Member

@anthonychu anthonychu left a comment

Choose a reason for hiding this comment

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

Works great. Thanks!

@anthonychu
Copy link
Member

@manekinekko Would be great to add a test for this. Do we have Cypress tests that test a dev server and not static?

@manekinekko
Copy link
Member

We don't. But we can update the static app to take into account fetching query params through JavaScript and making sure this implementation doesn't regress. cc @sgollapudi77 @Reshmi-Sriram

@sgollapudi77
Copy link
Contributor

We don't. But we can update the static app to take into account fetching query params through JavaScript and making sure this implementation doesn't regress. cc @sgollapudi77 @Reshmi-Sriram

I can create an open issue for testing this feature to work on and merge this PR now.

@anthonychu
Copy link
Member

I can create an open issue for testing this feature to work on and merge this PR now.

Great idea. Let’s get this merged and released soon. Let me know if I can help.

@sgollapudi77 sgollapudi77 merged commit d1ca45e into Azure:main Nov 24, 2021
@sgollapudi77 sgollapudi77 linked an issue Nov 24, 2021 that may be closed by this pull request
2 tasks
@sgollapudi77
Copy link
Contributor

Fixes #350 #346

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: rules engine Specific issues related to src/msha/routes-engine/**
Projects
None yet
4 participants