fix(nuxt): inline entry styles before component styles (#25749)

This commit is contained in:
Daniel Roe 2024-02-13 09:53:56 +00:00 committed by GitHub
parent 3ac8b18cb6
commit 795050e68c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -299,6 +299,9 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
nuxt: undefined!, /* NuxtApp */
payload: (ssrError ? { error: ssrError } : {}) as NuxtPayload,
_payloadReducers: {},
modules: new Set(),
set _registeredComponents(value) { this.modules = value },
get _registeredComponents() { return this.modules },
islandContext
}
@ -322,6 +325,13 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
writeEarlyHints(event, link)
}
if (process.env.NUXT_INLINE_STYLES && !isRenderingIsland) {
for (const id of await getEntryIds()) {
ssrContext.modules!.add(id)
}
}
const _rendered = await renderer.renderToString(ssrContext).catch(async (error) => {
// We use error to bypass full render if we have an early response we can make
if (ssrContext._renderResponse && error.message === 'skipping render') { return {} as ReturnType<typeof renderer['renderToString']> }
@ -356,18 +366,9 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
await payloadCache!.setItem(withoutTrailingSlash(url), renderPayloadResponse(ssrContext))
}
if (process.env.NUXT_INLINE_STYLES && !isRenderingIsland) {
const source = ssrContext.modules ?? ssrContext._registeredComponents
if (source) {
for (const id of await getEntryIds()) {
source.add(id)
}
}
}
// Render inline styles
const inlinedStyles = (process.env.NUXT_INLINE_STYLES || isRenderingIsland)
? await renderInlineStyles(ssrContext.modules ?? ssrContext._registeredComponents ?? [])
? await renderInlineStyles(ssrContext.modules ?? [])
: []
const NO_SCRIPTS = process.env.NUXT_NO_SCRIPTS || routeOptions.experimentalNoScripts