From 3a49fb02db302e3e5314892fd4cd4fb6ca3692e4 Mon Sep 17 00:00:00 2001 From: Julien Date: Mon, 28 Oct 2024 22:30:46 +0100 Subject: [PATCH] feat: support full-reload when boundary file not imported dynamically --- .changeset/spotty-donkeys-doubt.md | 5 +++++ packages/runner/src/serve.ts | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 .changeset/spotty-donkeys-doubt.md diff --git a/.changeset/spotty-donkeys-doubt.md b/.changeset/spotty-donkeys-doubt.md new file mode 100644 index 0000000..1787ea2 --- /dev/null +++ b/.changeset/spotty-donkeys-doubt.md @@ -0,0 +1,5 @@ +--- +'@hot-hook/runner': minor +--- + +The runner will now full-reload the application when a file changes and the boundaries are not dynamically imported. diff --git a/packages/runner/src/serve.ts b/packages/runner/src/serve.ts index e707484..cd97ce1 100644 --- a/packages/runner/src/serve.ts +++ b/packages/runner/src/serve.ts @@ -24,7 +24,7 @@ export class Serve extends BaseCommand { declare scriptArgs: string[] #httpServer?: ExecaChildProcess - #onReloadAsked?: (updatedFile: string) => void + #onReloadAsked?: (updatedFile: string, shouldBeReloadable: boolean) => void #onFileInvalidated?: (invalidatedFiles: string[]) => void /** @@ -57,7 +57,7 @@ export class Serve extends BaseCommand { if (typeof message !== 'object') return if ('type' in message && message.type === 'hot-hook:full-reload') { - this.#onReloadAsked?.(message.path) + this.#onReloadAsked?.(message.path, message.shouldBeReloadable) } if ('type' in message && message.type === 'hot-hook:invalidated') { @@ -82,11 +82,17 @@ export class Serve extends BaseCommand { this.#log(`Starting ${this.colors.green(this.script)}`) this.#startHTTPServer() - this.#onReloadAsked = (path) => { + this.#onReloadAsked = (path, shouldBeReloadable) => { this.#clearScreen() const relativePath = relative(process.cwd(), path) - this.#log(`${this.colors.green(relativePath)} changed. Restarting.`) + const message = `${this.colors.green(relativePath)} changed. Restarting.` + if (!shouldBeReloadable) { + this.#log(message) + } else { + const warning = `${this.colors.yellow('This file should be reloadable, but a parent boundary was not dynamically imported.')}` + this.#log(`${message}\n${warning}`) + } this.#httpServer?.removeAllListeners() this.#httpServer?.kill('SIGKILL')