Skip to content

Commit

Permalink
fix(nuxt): inline global css with ssr: false route rule (#21763)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jun 25, 2023
1 parent 5b83704 commit 4cc9a71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/nuxt/src/core/runtime/nitro/renderer.ts
Expand Up @@ -126,6 +126,7 @@ const getSPARenderer = lazyCachedFunction(async () => {

const renderToString = (ssrContext: NuxtSSRContext) => {
const config = useRuntimeConfig()
ssrContext.modules = ssrContext.modules || new Set<string>()
ssrContext!.payload = {
_errors: {},
serverRendered: false,
Expand Down
11 changes: 11 additions & 0 deletions test/basic.test.ts
Expand Up @@ -1169,6 +1169,17 @@ describe.skipIf(isDev() || isWebpack)('inlining component styles', () => {
}
})

it('should inline global css when accessing a page with `ssr: false` override via route rules', async () => {
const globalCSS = [
'{--plugin:"plugin"}', // CSS imported ambiently in JS/TS
'{--global:"global";' // global css from nuxt.config
]
const html = await $fetch('/route-rules/spa')
for (const style of globalCSS) {
expect(html).toContain(style)
}
})

it('should not include inlined CSS in generated CSS file', async () => {
const html: string = await $fetch('/styles')
const cssFiles = new Set([...html.matchAll(/<link [^>]*href="([^"]*\.css)">/g)].map(m => m[1]))
Expand Down
2 changes: 1 addition & 1 deletion test/bundle.test.ts
Expand Up @@ -35,7 +35,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM

it('default server bundle size', async () => {
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect.soft(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"63.9k"')
expect.soft(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"64.0k"')

const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2328k"')
Expand Down

0 comments on commit 4cc9a71

Please sign in to comment.