From f825eb54c40fa515dcae94ddb29f9787239dcad0 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 24 Sep 2024 13:03:09 +0100 Subject: [PATCH] fix(nuxt): add `crossorigin` attribute for stylesheets (#29138) --- packages/nuxt/src/core/runtime/nitro/renderer.ts | 4 ++-- test/basic.test.ts | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index e973d53f8e..4a7037ae44 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -385,7 +385,7 @@ export default defineRenderHandler(async (event): Promise { it('should not include inlined CSS in generated CSS file', async () => { const html: string = await $fetch('/styles') - const cssFiles = new Set([...html.matchAll(/]*href="([^"]*\.css)">/g)].map(m => m[1]!)) + const cssFiles = new Set([...html.matchAll(/]*href="([^"]*\.css)"(?: crossorigin)?>/g)].map(m => m[1]!)) let css = '' for (const file of cssFiles || []) { css += await $fetch(file) @@ -1831,11 +1831,7 @@ describe.skipIf(isDev() || isWebpack)('inlining component styles', () => { it('does not load stylesheet for page styles', async () => { const html: string = await $fetch('/styles') - expect(html.match(/]*href="[^"]*\.css">/g)?.filter(m => m.includes('entry'))?.map(m => m.replace(/\.[^.]*\.css/, '.css'))).toMatchInlineSnapshot(` - [ - "", - ] - `) + expect(html.match(/]*href="[^"]*\.css">(?: crossorigin)?/g)?.filter(m => m.includes('entry'))?.map(m => m.replace(/\.[^.]*\.css/, '.css'))).toMatchInlineSnapshot(`undefined`) }) it('still downloads client-only styles', async () => { @@ -2365,6 +2361,7 @@ describe('component islands', () => { { "link": [ { + "crossorigin": "", "href": "/_nuxt/components/islands/PureComponent.vue?vue&type=style&index=0&scoped=c0c0cf89&lang.css", "rel": "stylesheet", },