Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(remix-dev): ensure devServerPort config value is the same across reloads #3202

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
- SufianBabri
- supachaidev
- tascord
- tessellator
- TheRealAstoo
- therealflyingcoder
- thomasheyenbrock
Expand Down
5 changes: 5 additions & 0 deletions packages/remix-dev/__tests__/readConfig-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ describe("readConfig", () => {
`
);
});

it("returns the same devServerPort value across reloads", async () => {
let newConfig = await readConfig(remixRoot);
expect(newConfig.devServerPort).toBe(config.devServerPort);
});
});
10 changes: 9 additions & 1 deletion packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { defineConventionalRoutes } from "./config/routesConvention";
import { ServerMode, isValidServerMode } from "./config/serverModes";
import { serverBuildVirtualModule } from "./compiler/virtualModules";

/* eslint-disable prefer-let/prefer-let */
declare global {
var __devServerPort: number | undefined;
}

export interface RemixMdxConfig {
rehypePlugins?: any[];
remarkPlugins?: any[];
Expand Down Expand Up @@ -358,7 +363,10 @@ export async function readConfig(
process.env.REMIX_DEV_SERVER_WS_PORT || 8002
);
}
let devServerPort = await getPort({ port: appConfig.devServerPort });
if (!global.__devServerPort) {
global.__devServerPort = await getPort({ port: appConfig.devServerPort });
}
let devServerPort = global.__devServerPort;
// set env variable so un-bundled servers can use it
process.env.REMIX_DEV_SERVER_WS_PORT = `${devServerPort}`;
let devServerBroadcastDelay = appConfig.devServerBroadcastDelay || 0;
Expand Down