Skip to content

Commit

Permalink
feat: support full-reload when boundary file not imported dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Oct 28, 2024
1 parent aeda2c2 commit 3a49fb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-donkeys-doubt.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 10 additions & 4 deletions packages/runner/src/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Serve extends BaseCommand {
declare scriptArgs: string[]

#httpServer?: ExecaChildProcess<string>
#onReloadAsked?: (updatedFile: string) => void
#onReloadAsked?: (updatedFile: string, shouldBeReloadable: boolean) => void
#onFileInvalidated?: (invalidatedFiles: string[]) => void

/**
Expand Down Expand Up @@ -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') {
Expand All @@ -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')
Expand Down

0 comments on commit 3a49fb0

Please sign in to comment.