SSR import.meta.glob
does not update on file/directory add/remove
#2734
Labels
import.meta.glob
does not update on file/directory add/remove
#2734
Describe the bug
Suppose you have a
main.js
script usingimport.meta.glob('/src/pages/*.js')
.main.js
is an SSR-evaluated module. When the dev server is running and you add ac.js
file,main.js
is not updated with the new import. Similarly, deletinga.js
does not update the imports. Only updatingindex.js
directly seems to re-transform the file.It is notable that
import.meta.glob
is already able to respond to file/directory changes fine when used outside an SSR context, which is why I believe this is a bug and not a feature request. In addition, there is an explicit test for this exact scenario of adding/removing files againstimport.meta.glob
for non-SSR:vite/packages/playground/glob-import/__tests__/glob-import.spec.ts
Lines 54 to 67 in 2358dfc
Which indicates this is indeed supposed to be an existing feature.
A workaround for this is to re-save or
touch
your SSR file after every update to the directory.Reproduction
https://github.com/GrygrFlzr/vite-ssr-glob
git clone https://github.com/GrygrFlzr/vite-ssr-glob.git cd vite-ssr-glob npm install npm run dev
src/data/b.json
to the contents{}
. This will trigger HMR.Demonstrates correct update on file change.
src/data/c.json
with the contents{}
.Demonstrates lack of update on file addition.
src/data/a.json
.Demonstrates lack of update on file removal.
src/app.js
without changing its contents. This will invalidate the file and trigger HMR, correctly showing the current state of thesrc/data
directory.System Info
Used package manager: npm
The text was updated successfully, but these errors were encountered: