Skip to content

Commit e5d004d

Browse files
committed
Resolve root route file path
1 parent cdc7839 commit e5d004d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

packages/react-router-dev/vite/rsc/plugin.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type * as Vite from "vite";
22
import { init as initEsModuleLexer } from "es-module-lexer";
3+
import * as Path from "pathe";
34
import * as babel from "@babel/core";
45
import colors from "picocolors";
56

@@ -28,14 +29,23 @@ import { warnOnClientSourceMaps } from "../plugins/warn-on-client-source-maps";
2829

2930
export function reactRouterRSCVitePlugin(): Vite.PluginOption[] {
3031
let configLoader: ConfigLoader;
31-
let config: ResolvedReactRouterConfig;
3232
let typegenWatcherPromise: Promise<Typegen.Watcher> | undefined;
3333
let viteCommand: Vite.ConfigEnv["command"];
3434
let routeIdByFile: Map<string, string> | undefined;
3535
let logger: Vite.Logger;
3636

3737
const defaultEntries = getDefaultEntries();
3838

39+
let config: ResolvedReactRouterConfig;
40+
let rootRouteFile: string;
41+
function updateConfig(newConfig: ResolvedReactRouterConfig) {
42+
config = newConfig;
43+
rootRouteFile = Path.resolve(
44+
newConfig.appDirectory,
45+
newConfig.routes.root.file,
46+
);
47+
}
48+
3949
return [
4050
{
4151
name: "react-router/rsc",
@@ -75,7 +85,7 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] {
7585

7686
const configResult = await configLoader.getConfig();
7787
if (!configResult.ok) throw new Error(configResult.error);
78-
config = configResult.value;
88+
updateConfig(configResult.value);
7989

8090
if (
8191
viteUserConfig.base &&
@@ -246,7 +256,7 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] {
246256
});
247257

248258
// Update shared plugin config reference
249-
config = result.value;
259+
updateConfig(result.value);
250260

251261
if (configChanged || routeConfigChanged) {
252262
invalidateVirtualModules(viteDevServer);
@@ -315,7 +325,7 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] {
315325
id,
316326
viteCommand,
317327
routeIdByFile,
318-
rootRouteFile: config.routes.root.file,
328+
rootRouteFile,
319329
viteEnvironment: this.environment,
320330
});
321331
},

0 commit comments

Comments
 (0)