Skip to content

Commit

Permalink
fix(dev): kill app server when remix dev terminates
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Aug 29, 2023
1 parent 0060972 commit 8279059
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-chefs-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

kill app server when remix dev terminates
5 changes: 4 additions & 1 deletion packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ export async function dev(
let config = await readConfig(remixRoot);

let resolved = await resolveDevServe(config, flags);
await devServer_unstable.serve(config, resolved);
devServer_unstable.serve(config, resolved);

// keep `remix dev` alive by waiting indefinitely
await new Promise(() => {});
}

let clientEntries = ["entry.client.tsx", "entry.client.js", "entry.client.jsx"];
Expand Down
11 changes: 7 additions & 4 deletions packages/remix-dev/devServer_unstable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import prettyMs from "pretty-ms";
import execa from "execa";
import express from "express";
import pc from "picocolors";
import exitHook from "exit-hook";

import * as Channel from "../channel";
import { type Manifest } from "../manifest";
Expand All @@ -22,7 +23,7 @@ import type { Result } from "../result";
import { err, ok } from "../result";
import invariant from "../invariant";
import { logger } from "../tux";
import { kill, killtree } from "./proc";
import { killtree } from "./proc";

let detectBin = async (): Promise<string> => {
let pkgManager = detectPackageManager() ?? "npm";
Expand Down Expand Up @@ -267,12 +268,14 @@ export let serve = async (

server.listen(options.port);

return new Promise(() => {}).finally(async () => {
state.appServer?.pid && (await kill(state.appServer.pid));
let cleanup = async () => {
state.appServer?.kill();
websocket.close();
server.close();
await dispose();
});
};
exitHook(cleanup);
return cleanup;
};

let clean = (config: RemixConfig) => {
Expand Down

0 comments on commit 8279059

Please sign in to comment.