fix(nuxt): handle injecting multiple entry ids for styles (#21864)

This commit is contained in:
Daniel Roe 2023-06-30 05:25:43 +01:00 committed by GitHub
parent 5f5b9dfe99
commit 87e01ccf0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -66,7 +66,10 @@ const getClientManifest: () => Promise<Manifest> = () => import('#build/dist/ser
.then(r => r.default || r)
.then(r => typeof r === 'function' ? r() : r) as Promise<ClientManifest>
const getEntryId: () => Promise<string> = () => getClientManifest().then(r => Object.values(r).find(r => r.isEntry)!.src!)
const getEntryIds: () => Promise<string[]> = () => getClientManifest().then(r => Object.values(r).filter(r =>
// @ts-expect-error internal key set by CSS inlining configuration
r._globalCSS
).map(r => r.src!))
// @ts-expect-error virtual file
const getStaticRenderedHead = (): Promise<NuxtMeta> => import('#head-static').then(r => r.default || r)
@ -289,11 +292,11 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
const renderedMeta = await ssrContext.renderMeta?.() ?? {}
if (process.env.NUXT_INLINE_STYLES && !islandContext) {
const entryId = await getEntryId()
if (ssrContext.modules) {
ssrContext.modules.add(entryId)
} else if (ssrContext._registeredComponents) {
ssrContext._registeredComponents.add(entryId)
const source = ssrContext.modules ?? ssrContext._registeredComponents
if (source) {
for (const id of await getEntryIds()) {
source.add(id)
}
}
}

View File

@ -166,6 +166,10 @@ export async function bundle (nuxt: Nuxt) {
for (const key in manifest) {
const entry = manifest[key]
const shouldRemoveCSS = chunksWithInlinedCSS.has(key) && !entry.isEntry
if (entry.isEntry && chunksWithInlinedCSS.has(key)) {
// @ts-expect-error internal key
entry._globalCSS = true
}
if (shouldRemoveCSS && entry.css) {
entry.css = []
}