diff --git a/packages/wxt/src/core/create-server.ts b/packages/wxt/src/core/create-server.ts index 57c611982..fb0d95919 100644 --- a/packages/wxt/src/core/create-server.ts +++ b/packages/wxt/src/core/create-server.ts @@ -110,8 +110,13 @@ async function createServerInternal(): Promise { // Listen for file changes and reload different parts of the extension accordingly const reloadOnChange = createFileReloader(server); - server.watcher.on('all', reloadOnChange); - keyboardShortcuts.start(); + server.watcher.on('all', async (...args) => { + await reloadOnChange(args[0], args[1]); + + // Restart keyboard shortcuts after file is changed - for some reason they stop working. + keyboardShortcuts.start(); + }); + keyboardShortcuts.printHelp({ canReopenBrowser: !wxt.config.runnerConfig.config.disabled && !!runner.canOpen?.(), diff --git a/packages/wxt/src/core/keyboard-shortcuts.ts b/packages/wxt/src/core/keyboard-shortcuts.ts index 1330aaa71..0dfba0140 100644 --- a/packages/wxt/src/core/keyboard-shortcuts.ts +++ b/packages/wxt/src/core/keyboard-shortcuts.ts @@ -26,9 +26,7 @@ export function createKeyboardShortcuts( return { start() { - if (rl) return; - - rl = readline.createInterface({ + rl ??= readline.createInterface({ input: process.stdin, terminal: false, // Don't intercept ctrl+C, ctrl+Z, etc }); @@ -37,8 +35,7 @@ export function createKeyboardShortcuts( }, stop() { - rl?.close(); - rl = undefined; + rl?.removeListener('line', handleInput); }, printHelp(flags) {