Skip to content

Commit 0bf04dd

Browse files
committed
Ignore injected plugin context when using Environment API
1 parent 902fece commit 0bf04dd

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -601,33 +601,36 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
601601

602602
/** Mutates `ctx` as a side-effect */
603603
let updatePluginContext = async (): Promise<void> => {
604+
let reactRouterConfig: ResolvedReactRouterConfig;
605+
let reactRouterConfigResult = await reactRouterConfigLoader.getConfig();
606+
607+
if (reactRouterConfigResult.ok) {
608+
reactRouterConfig = reactRouterConfigResult.value;
609+
} else {
610+
logger.error(reactRouterConfigResult.error);
611+
if (firstLoad) {
612+
process.exit(1);
613+
}
614+
return;
615+
}
616+
604617
// This `injectedPluginContext` logic is so we can support injecting an
605618
// already-resolved plugin context into the build. This is so we can resolve
606619
// the plugin context once for the entire build process and avoid resolving
607620
// it every time the Vite config is resolved. This is most important for
608621
// resolving the `buildManifest` object since it involves executing the
609622
// `serverBundles` function, which we want to avoid doing multiple times.
623+
// Note that this logic is redundant when using the Vite Environment API
624+
// since our plugin is instantiated once and shared across all builds.
610625
let injectedPluginContext =
626+
!reactRouterConfig.future.unstable_viteEnvironmentApi &&
611627
viteCommand === "build"
612628
? extractPluginContext(viteUserConfig)
613629
: undefined;
614630
if (injectedPluginContext) {
615631
ctx = injectedPluginContext;
616632
}
617633

618-
let reactRouterConfig: ResolvedReactRouterConfig;
619-
let reactRouterConfigResult = await reactRouterConfigLoader.getConfig();
620-
621-
if (reactRouterConfigResult.ok) {
622-
reactRouterConfig = reactRouterConfigResult.value;
623-
} else {
624-
logger.error(reactRouterConfigResult.error);
625-
if (firstLoad) {
626-
process.exit(1);
627-
}
628-
return;
629-
}
630-
631634
let { entryClientFilePath, entryServerFilePath } = await resolveEntryFiles({
632635
rootDirectory,
633636
reactRouterConfig,

0 commit comments

Comments
 (0)