Skip to content

Remove unused Vite file system watcher #13133

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

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-otters-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-router/dev": patch
---

Remove unused Vite file system watcher
21 changes: 0 additions & 21 deletions packages/react-router-dev/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
configRoutesToRouteManifest,
} from "./routes";
import { detectPackageManager } from "../cli/detectPackageManager";
import { isReactRouterRepo } from "./is-react-router-repo";

const excludedConfigPresetKeys = ["presets"] as const satisfies ReadonlyArray<
keyof ReactRouterConfig
Expand Down Expand Up @@ -546,10 +545,6 @@ export async function createConfigLoader({
let viteNodeContext = await ViteNode.createContext({
root,
mode: watch ? "development" : "production",
server: !watch ? { watch: null } : {},
ssr: {
external: ssrExternals,
},
});

let reactRouterConfigFile = findEntry(root, "react-router.config", {
Expand Down Expand Up @@ -732,22 +727,6 @@ export async function resolveEntryFiles({
return { entryClientFilePath, entryServerFilePath };
}

export const ssrExternals = isReactRouterRepo()
? [
// This is only needed within this repo because these packages
// are linked to a directory outside of node_modules so Vite
// treats them as internal code by default.
"react-router",
"react-router-dom",
"@react-router/architect",
"@react-router/cloudflare",
"@react-router/dev",
"@react-router/express",
"@react-router/node",
"@react-router/serve",
]
: undefined;

const entryExts = [".js", ".jsx", ".ts", ".tsx"];

function findEntry(
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import * as VirtualModule from "./virtual-module";
import { resolveFileUrl } from "./resolve-file-url";
import { combineURLs } from "./combine-urls";
import { removeExports } from "./remove-exports";
import { ssrExternals } from "./ssr-externals";
import {
type RouteChunkName,
type RouteChunkExportName,
Expand All @@ -59,7 +60,6 @@ import {
type ConfigLoader,
createConfigLoader,
resolveEntryFiles,
ssrExternals,
configRouteToBranchRoute,
} from "../config/config";
import * as WithProps from "./with-props";
Expand Down
17 changes: 17 additions & 0 deletions packages/react-router-dev/vite/ssr-externals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { isReactRouterRepo } from "../config/is-react-router-repo";

export const ssrExternals = isReactRouterRepo()
? [
// This is only needed within this repo because these packages
// are linked to a directory outside of node_modules so Vite
// treats them as internal code by default.
"react-router",
"react-router-dom",
"@react-router/architect",
"@react-router/cloudflare",
"@react-router/dev",
"@react-router/express",
"@react-router/node",
"@react-router/serve",
]
: undefined;
46 changes: 26 additions & 20 deletions packages/react-router-dev/vite/vite-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,42 @@ import { installSourcemapsSupport } from "vite-node/source-map";
import type * as Vite from "vite";

import { preloadVite, getVite } from "./vite";
import { ssrExternals } from "./ssr-externals";

export type Context = {
devServer: Vite.ViteDevServer;
server: ViteNodeServer;
runner: ViteNodeRunner;
};

export async function createContext(
viteConfig: Vite.InlineConfig = {}
): Promise<Context> {
export async function createContext({
root,
mode,
}: {
root: Vite.UserConfig["root"];
mode: Vite.ConfigEnv["mode"];
}): Promise<Context> {
await preloadVite();
const vite = getVite();

const devServer = await vite.createServer(
vite.mergeConfig(
{
server: {
preTransformRequests: false,
hmr: false,
},
optimizeDeps: {
noDiscovery: true,
},
configFile: false,
envFile: false,
plugins: [],
},
viteConfig
)
);
const devServer = await vite.createServer({
root,
mode,
server: {
preTransformRequests: false,
hmr: false,
watch: null,
},
ssr: {
external: ssrExternals,
},
optimizeDeps: {
noDiscovery: true,
},
configFile: false,
envFile: false,
plugins: [],
});
await devServer.pluginContainer.buildStart({});

const server = new ViteNodeServer(devServer);
Expand Down