From 66b4552def1d8182b5a36e9f7951f27d84b5bb38 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Sun, 21 Sep 2025 11:21:45 -0700 Subject: [PATCH] fix Thread hot reloading --- src/shell.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shell.ts b/src/shell.ts index 15ba3fa..8bbc8b5 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -7,7 +7,9 @@ import { NOSE_SYS_BIN, NOSE_USR_BIN } from "./config" import { isFile } from "./utils" import { AsyncLocalStorage } from "async_hooks" -export const Thread = new AsyncLocalStorage() +// Ensure "Thread" lives between bun's hot reloads +const g = globalThis as typeof globalThis & { __thread?: AsyncLocalStorage } +export const Thread = g.__thread ??= new AsyncLocalStorage() type State = { id?: string