diff --git a/packages/tui/src/context/storage.tsx b/packages/tui/src/context/storage.tsx index adac30b440b..57f45a68f86 100644 --- a/packages/tui/src/context/storage.tsx +++ b/packages/tui/src/context/storage.tsx @@ -110,14 +110,20 @@ export function createStorage(root: string, channel: string) { }, } - let reload: ReturnType | undefined + let reloadTimer: ReturnType | undefined let watcher: ReturnType | undefined try { watcher = watch(directory, () => { - clearTimeout(reload) + clearTimeout(reloadTimer) // Atomic writes notify for the temporary file before its final rename, and some // platforms coalesce the rename event. Reload after the event burst has settled. - reload = setTimeout(() => entries.forEach((entry) => entry.reload()), 50) + reloadTimer = setTimeout(() => entries.forEach((entry) => entry.reload()), 50) + }) + watcher.on("error", (error) => { + clearTimeout(reloadTimer) + watcher?.close() + watcher = undefined + console.error("Storage directory watcher failed, live-reload disabled", { directory, error }) }) } catch (error) { // fs.watch throws synchronously (e.g. ENOSPC when the inotify watch limit is @@ -128,7 +134,7 @@ export function createStorage(root: string, channel: string) { return { storage, close: () => { - clearTimeout(reload) + clearTimeout(reloadTimer) watcher?.close() }, }