From dd913ce0d8e7218fb3cf259ed370a0c20bb32475 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sun, 25 Jun 2023 22:51:31 +0100 Subject: [PATCH] fix(vite): resolve css files without importer id first (#21770) --- packages/vite/src/plugins/ssr-styles.ts | 9 +++++---- test/basic.test.ts | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/plugins/ssr-styles.ts b/packages/vite/src/plugins/ssr-styles.ts index 66f8491ed0..b04c1c7420 100644 --- a/packages/vite/src/plugins/ssr-styles.ts +++ b/packages/vite/src/plugins/ssr-styles.ts @@ -138,8 +138,8 @@ export function ssrStylesPlugin (options: SSRStylePluginOptions): Plugin { const s = new MagicString(code) options.clientCSSMap[id] ||= new Set() for (const file of options.globalCSS) { - const resolved = await this.resolve(file, id) - const res = await this.resolve(file + '?inline&used', id) + const resolved = await this.resolve(file) ?? await this.resolve(file, id) + const res = await this.resolve(file + '?inline&used') ?? await this.resolve(file + '?inline&used', id) if (!resolved || !res) { if (!warnCache.has(file)) { warnCache.add(file) @@ -179,8 +179,9 @@ export function ssrStylesPlugin (options: SSRStylePluginOptions): Plugin { let styleCtr = 0 const ids = options.clientCSSMap[id] || [] for (const file of ids) { - const resolved = await this.resolve(file, id) - if (!resolved || !(await this.resolve(file + '?inline&used', id))) { + const resolved = await this.resolve(file) ?? await this.resolve(file, id) + const res = await this.resolve(file + '?inline&used') ?? await this.resolve(file + '?inline&used', id) + if (!resolved || !res) { if (!warnCache.has(file)) { warnCache.add(file) this.warn(`[nuxt] Cannot extract styles for \`${file}\`. Its styles will not be inlined when server-rendering.`) diff --git a/test/basic.test.ts b/test/basic.test.ts index 08597534ed..aea98b7ba7 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -1154,10 +1154,10 @@ describe.skipIf(isDev() || isWebpack)('inlining component styles', () => { '{--global:"global";', // global css from nuxt.config '{--assets:"assets"}', //