Skip to content

Commit 6cf82d6

Browse files
committed
fix(vite): loadEnv before reading routes
1 parent 919ea37 commit 6cf82d6

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

.changeset/six-rocks-love.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-router/dev": major
3+
---
4+
5+
Load vite env variables before reading routes.ts

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,20 +1279,20 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
12791279
});
12801280
}
12811281

1282-
reactRouterConfigLoader = await createConfigLoader({
1282+
await loadDotenv({
12831283
rootDirectory,
1284+
viteUserConfig,
12841285
mode,
1285-
watch: viteCommand === "serve",
12861286
});
12871287

1288-
await updatePluginContext();
1289-
1290-
await loadDotenv({
1288+
reactRouterConfigLoader = await createConfigLoader({
12911289
rootDirectory,
1292-
viteUserConfig,
12931290
mode,
1291+
watch: viteCommand === "serve",
12941292
});
12951293

1294+
await updatePluginContext();
1295+
12961296
let environments = await getEnvironmentsOptions(ctx, viteCommand, {
12971297
viteUserConfig,
12981298
});

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] {
6060
const rootDirectory = getRootDirectory(viteUserConfig);
6161
const watch = command === "serve";
6262

63+
await loadDotenv({
64+
rootDirectory,
65+
viteUserConfig,
66+
mode,
67+
});
68+
6369
configLoader = await createConfigLoader({
6470
rootDirectory,
6571
mode,
@@ -104,12 +110,6 @@ export function reactRouterRSCVitePlugin(): Vite.PluginOption[] {
104110
);
105111
}
106112

107-
await loadDotenv({
108-
rootDirectory,
109-
viteUserConfig,
110-
mode,
111-
});
112-
113113
const vite = await import("vite");
114114
logger = vite.createLogger(viteUserConfig.logLevel, {
115115
prefix: "[react-router]",

0 commit comments

Comments
 (0)