Skip to content

Commit f39a198

Browse files
bartlomiejuclaude
andauthored
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>
1 parent b3cb5b5 commit f39a198

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

packages/plugin-vite/src/mod.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@ export function fresh(config?: FreshViteConfig): Plugin[] {
9191
isDev = env.command === "serve";
9292

9393
return {
94+
server: {
95+
watch: {
96+
// Ignore temp files, editor swap files, and Vite timestamp
97+
// files. On Linux, these short-lived files can trigger a
98+
// watchFs race condition in Deno where the watcher tries to
99+
// open a file that has already been deleted, crashing the
100+
// dev server with ENOENT.
101+
ignored: [
102+
"**/*.tmp.*",
103+
"**/*.timestamp-*",
104+
"**/*~",
105+
"**/.#*",
106+
"**/*.swp",
107+
"**/*.swo",
108+
],
109+
},
110+
},
94111
esbuild: {
95112
jsx: "automatic",
96113
jsxImportSource: "preact",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { expect } from "@std/expect";
2+
import { fresh } from "../src/mod.ts";
3+
import type { Plugin } from "vite";
4+
5+
Deno.test("fresh plugin - sets server.watch.ignored patterns", () => {
6+
const plugins = fresh() as Plugin[];
7+
const freshPlugin = plugins.find((p) => p.name === "fresh");
8+
expect(freshPlugin).toBeDefined();
9+
10+
// Call the config hook as Vite would during dev
11+
// deno-lint-ignore no-explicit-any
12+
const configFn = freshPlugin!.config as any;
13+
const result = configFn({}, { command: "serve" });
14+
15+
const ignored = result?.server?.watch?.ignored;
16+
expect(ignored).toBeDefined();
17+
expect(Array.isArray(ignored)).toBe(true);
18+
19+
// Should ignore temp files, editor swap files, and Vite timestamp files
20+
expect(ignored).toContain("**/*.tmp.*");
21+
expect(ignored).toContain("**/*.timestamp-*");
22+
expect(ignored).toContain("**/*.swp");
23+
expect(ignored).toContain("**/*.swo");
24+
expect(ignored).toContain("**/*~");
25+
expect(ignored).toContain("**/.#*");
26+
});

0 commit comments

Comments
 (0)