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) <noreply@anthropic.com>
This commit is contained in:
Bartek Iwańczuk
2026-04-09 13:14:32 +02:00
committed by GitHub
co-authored by Claude Opus 4.6
parent b3cb5b5e31
commit f39a198f8d
2 changed files with 43 additions and 0 deletions
+17
View File
@@ -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",
+26
View File
@@ -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("**/.#*");
});