From 4de659c351589b83a83a7a42f3da5b071a625662 Mon Sep 17 00:00:00 2001 From: patak <583075+patak-dev@users.noreply.github.com> Date: Thu, 1 Aug 2024 17:03:43 +0200 Subject: [PATCH] fix: opt-in server.fs.cachedChecks (#17807) Co-authored-by: Bjorn Lu --- 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..dde3b345a64301 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** + +Caches filenames of accessed directories to avoid repeated filesystem operations. Particularly in Windows, this could result in a performance boost. It is disabled by default due to 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 (