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

Clean redundant ?client-route=1 usage in dev #9395

Merged

Conversation

markdalgleish
Copy link
Member

@markdalgleish markdalgleish commented May 9, 2024

This PR is aiming to address two things:

  1. Support the move to vite-plugin-react-swc: WIP: vite-plugin-react-swc integration #9092
  2. Potentially unlock this fix in Hydrogen: Serve assets from different domain in development Shopify/hydrogen#2078

The ?client-route=1 virtual modules that wrap all client routes are only necessary for a build optimisation that removes unused exports from route files on the client. The only reason these virtual modules were used in development was to keep the dev and build code paths as similar as possible. However, since it's causing other issues, and it also necessitated extra code in dev to special-case HMR for these files, we're opting to remove ?client-route=1 usage in dev entirely.

Copy link

changeset-bot bot commented May 9, 2024

🦋 Changeset detected

Latest commit: 93ca5d7

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 Patch
create-remix Patch
remix Patch
@remix-run/architect Patch
@remix-run/cloudflare Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/css-bundle Patch
@remix-run/deno Patch
@remix-run/eslint-config Patch
@remix-run/express Patch
@remix-run/node Patch
@remix-run/react Patch
@remix-run/serve Patch
@remix-run/server-runtime Patch
@remix-run/testing Patch

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

@@ -1271,8 +1269,8 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
cssModulesManifest[id] = code;
}

if (isClientRoute(id)) {
let routeModuleId = id.replace(CLIENT_ROUTE_QUERY_STRING, "");
if (id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Inlined isClientRoute here since it's now the only usage.

Comment on lines -1698 to -1701
if (isClientRoute(id)) {
return { code: addRefreshWrapper(ctx.remixConfig, code, id) };
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This code path is only used in dev, so no longer needed.

@@ -1789,17 +1783,16 @@ function addRefreshWrapper(
id: string
): string {
let route = getRoute(remixConfig, id);
let acceptExports =
route || isClientRoute(id)
Copy link
Member Author

Choose a reason for hiding this comment

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

HMR is no longer needed for these virtual modules since they're only used during build.

from the client build output. This is important in cases where custom route
exports are only ever used on the server. Without this optimization we can't
tree-shake any unused custom exports because routes are entry points. */
const BUILD_CLIENT_ROUTE_QUERY_STRING = "?__remix-build-client-route";
Copy link
Member Author

Choose a reason for hiding this comment

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

Since this query string is no longer visible in the browser's network tab, I'm not trying to make this look pretty anymore and instead I'm aiming for it to be more explicit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also the =1 suffix is no longer needed since that was to solve an issue when proxying during development. In production builds this query string never goes over the network.

@pcattori pcattori merged commit 45c7552 into dev May 9, 2024
9 checks passed
@pcattori pcattori deleted the markdalgleish/clean-client-route-virtual-module-in-dev branch May 9, 2024 02:41
@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting release This issue has been fixed and will be released soon package:dev vite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants