Is it possible to have Nitro update when virtual modules are invalidated during handleHotUpdate?
From a custom vite plugin the following works great:
Client side responds appropriately but I can't seem to get the SSR to see the changes in the virtual module. On reload it loads the old info and then hydrates with the correct info.
Any help would be greatly appreciated!!!
Any help would be greatly appreciated!!!
3 Replies
Hi @Gary. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources provided, there isn't enough specific information to directly answer your question about Nitro updating when virtual modules are invalidated during handleHotUpdate. The documents don't contain details about this particular scenario or the interaction between Vite's hot module replacement and Nitro's virtual modules.
However, I can provide some relevant information that might be helpful:
1. Nitro does support virtual modules. According to the Nitro configuration documentation (https://nitro.unjs.io/config#virtual), you can define virtual modules using the
virtual
option in the Nitro config. This allows you to create dynamic virtual import names and their contents.
2. Nuxt, which uses Nitro as its server engine, supports hot module replacement for the server part of the application. As mentioned in the Nuxt server documentation (https://nuxt.com/docs/getting-started/server), it supports "hot module replacement and auto-import like the other parts of your Nuxt application."
3. The Nuxt Kit documentation (https://nuxt.com/docs/api/kit/nitro) mentions utilities for working with Nitro, including adding server handlers and plugins. However, it doesn't specifically address updating virtual modules during hot updates.
Given the lack of specific information about your use case in the provided knowledge sources, I would recommend reaching out to the Nuxt or Nitro community forums or GitHub issues for more targeted assistance with this particular scenario. It's possible that achieving what you're trying to do might require some custom configuration or a workaround that isn't documented in the standard documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@477504252344795136> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
I created a reproduction of this issue on stackblitz here:
https://stackblitz.com/edit/github-3grtb9?file=app.vue
In the attached reproduction edit anything on app.vue and refresh the browser pane and you'll notice the time changes on the clientside after hydration but the serverside is stuck at the time the dev server was started.
Maybe there is something I'm missing in my vitePlugin.ts in my invalidation of that module. I do see in the terminal the invalidation take place.
Gary Williams
StackBlitz
Nuxt - Starter - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.