From c847d3a8faa5e2accb1b92a3564c1cb5c2825d8e Mon Sep 17 00:00:00 2001 From: Mark Dalgleish Date: Wed, 14 Feb 2024 11:22:00 +1100 Subject: [PATCH] Simplify Vite client route query string logic (#8748) --- packages/remix-dev/vite/plugin.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/remix-dev/vite/plugin.ts b/packages/remix-dev/vite/plugin.ts index bbaa19bddb0..10d502d105e 100644 --- a/packages/remix-dev/vite/plugin.ts +++ b/packages/remix-dev/vite/plugin.ts @@ -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 = [ @@ -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 = ( @@ -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,