Skip to content

New files added after dev start are not served if public is outside the root. #16503

@Shakeskeyboarde

Description

@Shakeskeyboarde

Describe the bug

I keep my Vite config (also index.html, tsconfig.json, etc.) inside my src directory. Inside my Vite config, I change the working directory to __dirname (ESM polyfilled). The root is left as default, which results in it being the directory which contains the Vite config, which is src. The publicDir option is set to ../public, which is outside the root.

With the above setup, if I start the dev server, then add a file to the public directory (eg. foo.txt, then attempt to open it in the browser (eg. http://localhost:5173/foo.txt), I will be served the SPA default and not the text file I just added.

Reproduction

https://stackblitz.com/edit/vitejs-vite-wxmhrw

Steps to reproduce

Open the stackblitz. The dev server should start automatically. Add a foo.txt file to the public directory. Append /foo.txt to the preview window URL. The contents of the text file will not be displayed.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.3 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^5.2.8 => 5.2.10

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions