Closed someguy20336 closed 10 months ago
Hi, that's because the IViteManifest
service is registered as Singleton by default, so the manifest.json
file is loaded once on first request. Subsequent changes are not read by the service.
You can actually change this behavior by using another lifetime like Scoped or Transient. The AddViteServices method defines a parameter to achieve this.
If there's a better way to manage the manifest using ASP.NET APIs, feel free to open a new PR for that.
Good point - I didn't think about changing the scope of the service, though that of course comes at the cost of reading it every time.
Let me think about how maybe the standard configuration API might work with this file. I'll open a PR if I think of something cool.
Describe the bug If you have a running ASP.NET Core site and you compile and deploy a new build of the client files only (no new binaries so the site doesn't need to restart),
ViteManifest
will still have the old manifest loaded in memory and attempt to serve files that may no longer exist (because the hash changed, for example). This causes any affected page to no longer render due to missing scripts.To Reproduce Steps to reproduce the behavior:
vite build
)vite build
. Presumably, you have different hashes of the file nowExpected behavior
Vite.AspNetCore
should watch the manifest file for changes. If the file is updated, it should invalidate the cached data and reload.Device (please complete the following information):
Additional context Note that, while I didn't actually try this out yet, it is possible that a workaround could be to implement your own
IViteManifest
wrapper aroundViteManifest
and add this behavior. Still, I would imagine it should ultimately be built into this library since I don't think there is a reason you wouldn't want this behavior.The FileProvider may be of interest here.
Might be interested in taking the PR if I have a chance here and you agree with the proposed change. But feel free to take it if you feel like you can knock it out quickly.