Skip to content

Commit

Permalink
Simplify Vite client route query string logic (remix-run#8748)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Feb 14, 2024
1 parent d284e52 commit c847d3a
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const CLIENT_ROUTE_EXPORTS = [
"shouldRevalidate",
];

const CLIENT_ROUTE_QUERY_STRING = "?client-route";
// The "=1" suffix ensures client route requests can be processed before hitting
// the Vite plugin since "?client-route" can be serialized as "?client-route="
const CLIENT_ROUTE_QUERY_STRING = "?client-route=1";

// Only expose a subset of route properties to the "serverBundles" function
const branchRouteProperties = [
Expand Down Expand Up @@ -249,10 +251,7 @@ const getHash = (source: BinaryLike, maxLength?: number): string => {
};

const isClientRoute = (id: string): boolean => {
return (
id.endsWith(CLIENT_ROUTE_QUERY_STRING) ||
id.endsWith(`${CLIENT_ROUTE_QUERY_STRING}=`) // Needed in case url gets preprocessed by any WHATWG searchParam serializer
);
return id.endsWith(CLIENT_ROUTE_QUERY_STRING);
};

const resolveChunk = (
Expand Down Expand Up @@ -1099,10 +1098,6 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {

if (isClientRoute(id)) {
let routeModuleId = id.replace(CLIENT_ROUTE_QUERY_STRING, "");
routeModuleId = routeModuleId.replace(
`${CLIENT_ROUTE_QUERY_STRING}=`,
""
);
let sourceExports = await getRouteModuleExports(
viteChildCompiler,
ctx,
Expand Down

0 comments on commit c847d3a

Please sign in to comment.