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

Fix Vite client route requests with pre-processed search params #8740

Merged
merged 4 commits into from
Feb 13, 2024

Conversation

cythrawll
Copy link
Contributor

@cythrawll cythrawll commented Feb 12, 2024

Issue if you have middleware that pass query string through any processing. anything WHATWG compatible will render a query param without a value ending with = this breaks matching in the vite plugin.

Included code so that vite plugin will match against the supported query string if it ends in '='.

another solution would just change the query string to something a bit more compatible like ?client-route=1 Would be willing to open a PR for that. I went for this one due to it being compatible with current solution.

Testing Strategy:

Tested on a custom express server that had a searchParams filter that parses the query string that transforms ?client-route into ?client-route= because of how WhatWG URL serializes searchParams.

the middleware mock basically looks like this (with 'http-hook' package installed):

process.on('httpHooks:request', (req) => {
  const url = new URL(req.url, `http://localhost:3000`);
  const searchParams = url.searchParams;
  req.url = `${url.pathname}?${url.searchParams}`;
});

see stackblitz: https://stackblitz.com/edit/remix-run-remix-xzvnld?file=server.ts

Came across this because I have some security hooks/middleware that process the query string.

Copy link

changeset-bot bot commented Feb 12, 2024

🦋 Changeset detected

Latest commit: a45f60b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@remix-run/dev Minor
create-remix Minor
remix Minor
@remix-run/architect Minor
@remix-run/cloudflare Minor
@remix-run/cloudflare-pages Minor
@remix-run/cloudflare-workers Minor
@remix-run/css-bundle Minor
@remix-run/deno Minor
@remix-run/eslint-config Minor
@remix-run/express Minor
@remix-run/node Minor
@remix-run/react Minor
@remix-run/serve Minor
@remix-run/server-runtime Minor
@remix-run/testing Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cythrawll cythrawll changed the title Fix: Support query string match in vite dev server WHATWG searchParams Fix (vite): Support query string match in vite dev server WHATWG searchParams Feb 12, 2024
@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Feb 12, 2024

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@pcattori pcattori added the vite label Feb 13, 2024
Copy link
Member

@markdalgleish markdalgleish left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@markdalgleish markdalgleish changed the title Fix (vite): Support query string match in vite dev server WHATWG searchParams Fix Vite client route requests with pre-processed search params Feb 13, 2024
@markdalgleish markdalgleish merged commit d284e52 into remix-run:dev Feb 13, 2024
9 checks passed
Copy link
Contributor

🤖 Hello there,

We just published version 2.7.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 2.7.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants