(clientServer)
| 239 | name: 'nuxt:vite-node-server', |
| 240 | enforce: 'post', |
| 241 | async configureServer (clientServer) { |
| 242 | // early return if plugins are 'borrowed' for testing/storybook |
| 243 | if (!tryUseNuxt()) { |
| 244 | return |
| 245 | } |
| 246 | |
| 247 | // When `ssr: false` without the vite environment API, the client dev server's |
| 248 | // config only carries the client entry, so we resolve the SPA entry up front. |
| 249 | const spaEntryPath = !nuxt.options.ssr && !nuxt.options.experimental.viteEnvironmentApi |
| 250 | ? await resolvePath(join(nuxt.options.appDir, 'entry-spa')) |
| 251 | : undefined |
| 252 | |
| 253 | // The SSR module graph isn't reachable from the file watcher or the |
| 254 | // `app:templatesGenerated` hook for modules invalidated by user plugins |
| 255 | // (e.g. virtual modules invalidated via `handleHotUpdate`). Track the |
| 256 | // most recent invalidation/HMR timestamp we've observed so we can pick |
| 257 | // up any module whose timestamp advanced since the previous SSR render. |
| 258 | // See https://github.com/nuxt/nuxt/issues/30169. |
| 259 | let lastSeenTimestamp = 0 |
| 260 | |
| 261 | function collectInvalidatedSsrModules (ssrServer: ViteDevServer) { |
| 262 | const ssrModuleGraph = nuxt.options.experimental.viteEnvironmentApi |
| 263 | ? ssrServer.environments.ssr.moduleGraph |
| 264 | : ssrServer.moduleGraph |
| 265 | let maxSeen = lastSeenTimestamp |
| 266 | for (const mod of ssrModuleGraph.idToModuleMap.values()) { |
| 267 | const modTimestamp = Math.max(mod.lastHMRTimestamp, mod.lastInvalidationTimestamp) |
| 268 | if (modTimestamp > lastSeenTimestamp) { |
| 269 | markInvalidate(mod) |
| 270 | if (modTimestamp > maxSeen) { |
| 271 | maxSeen = modTimestamp |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | lastSeenTimestamp = maxSeen |
| 276 | } |
| 277 | |
| 278 | function resolveServer (ssrServer: ViteDevServer) { |
| 279 | const viteNodeServerOptions = { |
| 280 | socketPath, |
| 281 | root: nuxt.options.srcDir, |
| 282 | entryPath: spaEntryPath ?? resolveServerEntry(ssrServer.config), |
| 283 | base: '/', |
| 284 | maxRetryAttempts: nuxt.options.vite.viteNode?.maxRetryAttempts, |
| 285 | baseRetryDelay: nuxt.options.vite.viteNode?.baseRetryDelay, |
| 286 | maxRetryDelay: nuxt.options.vite.viteNode?.maxRetryDelay, |
| 287 | requestTimeout: nuxt.options.vite.viteNode?.requestTimeout, |
| 288 | // TODO: remove baseURL in future |
| 289 | baseURL: nuxt.options.devServer.url, |
| 290 | } |
| 291 | |
| 292 | process.env.NUXT_VITE_NODE_OPTIONS = JSON.stringify(viteNodeServerOptions) |
| 293 | |
| 294 | socketServer = createViteNodeSocketServer(nuxt, ssrServer, clientServer, invalidates, () => collectInvalidatedSsrModules(ssrServer), viteNodeServerOptions) |
| 295 | } |
| 296 | |
| 297 | if (nuxt.options.experimental.viteEnvironmentApi || !nuxt.options.ssr) { |
| 298 | resolveServer(clientServer) |
nothing calls this directly
no test coverage detected
searching dependent graphs…