From f39a198f8d96f8316e619d124bac910c4a6aa55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 9 Apr 2026 11:14:32 +0000 Subject: [PATCH] fix: ignore temp files in Vite watcher to prevent dev server crash (#3763) ## Summary - Adds default `server.watch.ignored` patterns to the Fresh Vite plugin config - Ignores `*.tmp.*`, `*.timestamp-*`, editor swap files (`*.swp`, `*.swo`, `*~`, `.#*`) - Prevents a `watchFs` race condition on Linux where Deno tries to open a short-lived file that was already deleted, crashing the dev server with `NotFound: No such file or directory` Users can still override or extend these patterns in their own `vite.config.ts` since Vite merges config from plugins. Closes #3585 --------- Co-authored-by: Claude Opus 4.6 (1M context) --- packages/plugin-vite/src/mod.ts | 17 +++++++++++++++ packages/plugin-vite/tests/config_test.ts | 26 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 packages/plugin-vite/tests/config_test.ts diff --git a/packages/plugin-vite/src/mod.ts b/packages/plugin-vite/src/mod.ts index cd411cac..c49c2445 100644 --- a/packages/plugin-vite/src/mod.ts +++ b/packages/plugin-vite/src/mod.ts @@ -91,6 +91,23 @@ export function fresh(config?: FreshViteConfig): Plugin[] { isDev = env.command === "serve"; return { + server: { + watch: { + // Ignore temp files, editor swap files, and Vite timestamp + // files. On Linux, these short-lived files can trigger a + // watchFs race condition in Deno where the watcher tries to + // open a file that has already been deleted, crashing the + // dev server with ENOENT. + ignored: [ + "**/*.tmp.*", + "**/*.timestamp-*", + "**/*~", + "**/.#*", + "**/*.swp", + "**/*.swo", + ], + }, + }, esbuild: { jsx: "automatic", jsxImportSource: "preact", diff --git a/packages/plugin-vite/tests/config_test.ts b/packages/plugin-vite/tests/config_test.ts new file mode 100644 index 00000000..cd650105 --- /dev/null +++ b/packages/plugin-vite/tests/config_test.ts @@ -0,0 +1,26 @@ +import { expect } from "@std/expect"; +import { fresh } from "../src/mod.ts"; +import type { Plugin } from "vite"; + +Deno.test("fresh plugin - sets server.watch.ignored patterns", () => { + const plugins = fresh() as Plugin[]; + const freshPlugin = plugins.find((p) => p.name === "fresh"); + expect(freshPlugin).toBeDefined(); + + // Call the config hook as Vite would during dev + // deno-lint-ignore no-explicit-any + const configFn = freshPlugin!.config as any; + const result = configFn({}, { command: "serve" }); + + const ignored = result?.server?.watch?.ignored; + expect(ignored).toBeDefined(); + expect(Array.isArray(ignored)).toBe(true); + + // Should ignore temp files, editor swap files, and Vite timestamp files + expect(ignored).toContain("**/*.tmp.*"); + expect(ignored).toContain("**/*.timestamp-*"); + expect(ignored).toContain("**/*.swp"); + expect(ignored).toContain("**/*.swo"); + expect(ignored).toContain("**/*~"); + expect(ignored).toContain("**/.#*"); +});