From 1fa2567b0f4054fbc56f377d55a00a1bcbac3026 Mon Sep 17 00:00:00 2001 From: patak-dev Date: Thu, 1 Aug 2024 16:09:51 +0200 Subject: [PATCH] fix: opt-in server.fs.cachedChecks --- docs/config/server-options.md | 8 ++++++++ packages/vite/src/node/fsUtils.ts | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/config/server-options.md b/docs/config/server-options.md index a9d5d52df3c826..46c7e1d95e355c 100644 --- a/docs/config/server-options.md +++ b/docs/config/server-options.md @@ -328,6 +328,14 @@ export default defineConfig({ Blocklist for sensitive files being restricted to be served by Vite dev server. This will have higher priority than [`server.fs.allow`](#server-fs-allow). [picomatch patterns](https://github.com/micromatch/picomatch#globbing-features) are supported. +## server.fs.cachedChecks + +- **Type:** `boolean` +- **Default:** `false` +- **Experimental** + +The `fs.cachedChecks` optimization caches filenames of accessed directories to avoid repeated filesystem operations. In Windows in particular, this could result in a performance boost. It is disabled by default because there are edge cases when writing a file in a cached folder and immediately importing it. + ## server.origin - **Type:** `string` diff --git a/packages/vite/src/node/fsUtils.ts b/packages/vite/src/node/fsUtils.ts index 0377d5824e2aae..a295d4fc41adb6 100644 --- a/packages/vite/src/node/fsUtils.ts +++ b/packages/vite/src/node/fsUtils.ts @@ -46,12 +46,14 @@ export function getFsUtils(config: ResolvedConfig): FsUtils { if (!fsUtils) { if ( config.command !== 'serve' || - config.server.fs.cachedChecks === false || + config.server.fs.cachedChecks !== true || config.server.watch?.ignored || process.versions.pnp ) { // cached fsUtils is only used in the dev server for now - // it is enabled by default only when there aren't custom watcher ignored patterns configured + // it is disabled by default due to potential edge cases when writing a file + // and reading it immediately + // It is also disabled when there aren't custom watcher ignored patterns configured // and if yarn pnp isn't used fsUtils = commonFsUtils } else if (