Skip to content

Commit

Permalink
feat(dev,server-runtime): detect built mode via build.mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Jul 26, 2023
1 parent 1989865 commit 7cd6164
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .changeset/curly-moons-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@remix-run/dev": minor
"@remix-run/server-runtime": minor
---

detect built mode via `build.mode`

Prevents mode mismatch between built Remix server entry and user-land server.
Additionally, all runtimes (including non-Node runtimes) can use `build.mode` to determine if HMR should be performed.
2 changes: 1 addition & 1 deletion packages/remix-dev/__tests__/fixtures/cloudflare/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import * as build from "@remix-run/dev/server-build";
export const onRequest = createPagesFunctionHandler({
build,
getLoadContext: (context) => context.env,
mode: process.env.NODE_ENV,
mode: build.mode,
});
2 changes: 1 addition & 1 deletion packages/remix-dev/__tests__/fixtures/deno/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as build from "@remix-run/dev/server-build";

const remixHandler = createRequestHandlerWithStaticFiles({
build,
mode: Deno.env.get("NODE_ENV"),
mode: build.mode,
getLoadContext: () => ({}),
});

Expand Down
1 change: 1 addition & 0 deletions packages/remix-dev/compiler/server/plugins/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ${Object.keys(config.routes)
)};`;
})
.join("\n")}
export const mode = ${JSON.stringify(options.mode)};
export { default as assets } from ${JSON.stringify(
assetsManifestVirtualModule.id
)};
Expand Down
1 change: 1 addition & 0 deletions packages/remix-dev/server-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ throw new Error(
" by the Remix compiler at build time."
);

export const mode: ServerBuild["mode"] = undefined!;
export const assets: ServerBuild["assets"] = undefined!;
export const entry: ServerBuild["entry"] = undefined!;
export const routes: ServerBuild["routes"] = undefined!;
Expand Down
1 change: 1 addition & 0 deletions packages/remix-server-runtime/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { AppLoadContext } from "./data";
* The output of the compiler for the server build.
*/
export interface ServerBuild {
mode: string;
entry: {
module: ServerEntryModule;
};
Expand Down

0 comments on commit 7cd6164

Please sign in to comment.