fix(vite): include more of warmup within try/catch (#24072)

This commit is contained in:
Daniel Roe 2023-11-02 10:35:32 +01:00 committed by GitHub
parent ec317befc0
commit dc04f28cff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,6 +36,7 @@ export async function warmupViteServer (
const warmedUrls = new Set<String>() const warmedUrls = new Set<String>()
const warmup = async (url: string) => { const warmup = async (url: string) => {
try {
url = normaliseURL(url, server.config.base) url = normaliseURL(url, server.config.base)
if (warmedUrls.has(url)) { return } if (warmedUrls.has(url)) { return }
@ -45,18 +46,21 @@ export async function warmupViteServer (
return return
} }
warmedUrls.add(url) warmedUrls.add(url)
try {
await server.transformRequest(url, { ssr: isServer }) await server.transformRequest(url, { ssr: isServer })
} catch (e) { } catch (e) {
logger.debug('Warmup for %s failed with: %s', url, e) logger.debug('[nuxt] warmup for %s failed with: %s', url, e)
} }
// Don't warmup CSS file dependencies as they have already all been loaded to produce result // Don't warmup CSS file dependencies as they have already all been loaded to produce result
if (isCSSRequest(url)) { return } if (isCSSRequest(url)) { return }
try {
const mod = await server.moduleGraph.getModuleByUrl(url, isServer) const mod = await server.moduleGraph.getModuleByUrl(url, isServer)
const deps = mod?.ssrTransformResult?.deps /* server */ || Array.from(mod?.importedModules /* client */ || []).map(m => m.url) const deps = mod?.ssrTransformResult?.deps /* server */ || Array.from(mod?.importedModules /* client */ || []).map(m => m.url)
await Promise.all(deps.map(m => warmup(m))) await Promise.all(deps.map(m => warmup(m)))
} catch (e) {
logger.debug('[warmup] tracking dependencies for %s failed with: %s', url, e)
}
} }
await Promise.all(entries.map(entry => warmup(fileToUrl(entry, server.config.root)))) await Promise.all(entries.map(entry => warmup(fileToUrl(entry, server.config.root))))