Skip to content
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/fine-bats-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router-hono-server": patch
---

Add compatibility with environment API being promoted to v8 instead of unstable in React Router
22 changes: 14 additions & 8 deletions src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,18 @@ export function reactRouterHonoServer(options: ReactRouterHonoServerPluginOption
return;
}

const isEnvironmentApiEnabled =
pluginConfig.future.unstable_viteEnvironmentApi ??
(pluginConfig.future as { v8_viteEnvironmentApi?: boolean }).v8_viteEnvironmentApi;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure whether you'd prefer casting or ts-expect-error here. Currently in dependencies there's a version before this being promoted to v8. However, one of this will always error. I guess the back-compat could be removed shortly in the future, as environment API support was marked as experimental?


const flagName = pluginConfig.future.unstable_viteEnvironmentApi
? "unstable_viteEnvironmentApi"
: "v8_viteEnvironmentApi";

const serverEntryPoint = pluginConfig.serverEntryPoint;

if (pluginConfig.future.unstable_viteEnvironmentApi) {
console.warn(
"\x1b[33mThe unstable_viteEnvironmentApi is enabled.\nThis is experimental and may break your build.\x1b[0m\n"
);
if (isEnvironmentApiEnabled) {
console.warn(`\x1b[33mThe ${flagName} is enabled.\nThis is experimental and may break your build.\x1b[0m\n`);
}

if (
Expand Down Expand Up @@ -140,7 +146,7 @@ export function reactRouterHonoServer(options: ReactRouterHonoServerPluginOption
},
} satisfies UserConfig;

if (!pluginConfig.future.unstable_viteEnvironmentApi && !pluginConfig.isSsrBuild) {
if (!isEnvironmentApiEnabled && !pluginConfig.isSsrBuild) {
return baseConfig;
}

Expand All @@ -160,9 +166,9 @@ export function reactRouterHonoServer(options: ReactRouterHonoServerPluginOption
};
}

if (runtime === "bun" && pluginConfig.future.unstable_viteEnvironmentApi) {
if (runtime === "bun" && isEnvironmentApiEnabled) {
throw new Error(
"The unstable_viteEnvironmentApi is not supported with the Bun runtime. Please disable it in your react-router.config.ts"
`The ${flagName} is not supported with the Bun runtime. Please disable it in your react-router.config.ts`
);
}

Expand Down Expand Up @@ -215,7 +221,7 @@ export function reactRouterHonoServer(options: ReactRouterHonoServerPluginOption
},
} satisfies Omit<UserConfig, "plugins">;

if (pluginConfig.future.unstable_viteEnvironmentApi) {
if (isEnvironmentApiEnabled) {
return {
...baseConfig,
environments: {
Expand Down
Loading