Skip to content

Commit

Permalink
fix(nuxt): render inlined ssr styles before stylesheets (nuxt#22986)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Sep 4, 2023
1 parent 16d47ea commit 5f176b1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/nuxt/src/core/runtime/nitro/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { HeadEntryOptions } from '@unhead/schema'
import { defineRenderHandler, getRouteRules, useRuntimeConfig, useStorage } from '#internal/nitro'
import { useNitroApp } from '#internal/nitro/app'

import type { Link, Script } from '@unhead/vue'
import type { Link, Script, Style } from '@unhead/vue'
import { createServerHead } from '@unhead/vue'
// @ts-expect-error virtual file
import unheadPlugins from '#internal/unhead-plugins.mjs'
Expand Down Expand Up @@ -349,12 +349,12 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
}

// 2. Styles
head.push({ style: inlinedStyles })
head.push({
link: Object.values(styles)
.map(resource =>
({ rel: 'stylesheet', href: renderer.rendererContext.buildAssetsURL(resource.file) })
),
style: inlinedStyles
)
}, headEntryOptions)

if (!NO_SCRIPTS) {
Expand Down Expand Up @@ -495,7 +495,7 @@ function renderHTMLDocument (html: NuxtRenderHTMLContext) {
</html>`
}

async function renderInlineStyles (usedModules: Set<string> | string[]) {
async function renderInlineStyles (usedModules: Set<string> | string[]): Promise<Style[]> {
const styleMap = await getSSRStyles()
const inlinedStyles = new Set<string>()
for (const mod of usedModules) {
Expand Down

0 comments on commit 5f176b1

Please sign in to comment.