Skip to content

Commit

Permalink
fix(nuxt): inline entry styles before component styles (#25749)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 13, 2024
1 parent 3ac8b18 commit 795050e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/nuxt/src/core/runtime/nitro/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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']> }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 795050e

Please sign in to comment.