Hot update behaves quite erratically
There are some issues right now with hot update (i.e. auto refresh on file change during development) using Vite:
Adding a new markdown page in the directory doesn't trigger anything
This (I think) is a normal behavior from Vite and has to do with how Chokidar works or is called by Vite.
There is a way to give custom options to Chokidar but none of them seem to allow watching an extra folder.
Changing a markdown page doesn't always trigger a refresh
This is more problematic, and seems to happen because of the chunk-splitting/lazy-loading optimization.
It appears that a page change doesn't trigger an update if the page itself hasn't been loaded by Vite yet.
For example, if you start the development server and only load a component that shows the content of the pages' metadata (like a blog summary) then change the metadata inside one of the pages, it won't trigger a refresh.
But if you load the markdown page, go back to the blog summary, then any change to the file will trigger a refresh.
Looking at the debug logs (vite --debug
):
vite:hmr [file change] src/pages/2023-03-13_lorem-ipsum.mdx +11s
vite:hmr [propagate update] stop propagation because not analyzed: /home/ubuntu/workspace/rollup-plugin-pages-demo/src/pages/2023-03-13_lorem-ipsum.mdx +0ms
vite:hmr no update happened src/pages/2023-03-13_lorem-ipsum.mdx +0ms
It seems the file change is detected, but ignored by Vite.