From 83949c37341d1cfbedbca94d04b42f029bfab21a Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 10 Sep 2022 10:43:17 +0100 Subject: [PATCH] fix(nuxt): always inline entry styles (#7386) --- packages/nuxt/src/core/runtime/nitro/renderer.ts | 2 +- packages/vite/src/plugins/ssr-styles.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index ce6c682ff1..65e40cc6a6 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -224,7 +224,7 @@ function renderHTMLDocument (html: NuxtRenderHTMLContext) { async function renderInlineStyles (usedModules: Set | string[]) { const styleMap = await getSSRStyles() const inlinedStyles = new Set() - for (const mod of usedModules) { + for (const mod of ['entry', ...usedModules]) { if (mod in styleMap) { for (const style of await styleMap[mod]()) { inlinedStyles.add(``) diff --git a/packages/vite/src/plugins/ssr-styles.ts b/packages/vite/src/plugins/ssr-styles.ts index 84232ed721..7015728534 100644 --- a/packages/vite/src/plugins/ssr-styles.ts +++ b/packages/vite/src/plugins/ssr-styles.ts @@ -60,11 +60,11 @@ export function ssrStylesPlugin (options: SSRStylePluginOptions): Plugin { source: [ ...globalStylesArray.map((css, i) => `import style_${i} from './${css}';`), - `const globalStyles = [${globalStylesArray.map((_, i) => `style_${i}`).join(', ')}]`, - 'const resolveStyles = r => globalStyles.concat(r.default || r || [])', - `export default ${genObjectFromRawEntries( - Object.entries(emitted).map(([key, value]) => [key, `() => import('./${this.getFileName(value)}').then(resolveStyles)`]) - )}` + 'const interopDefault = r => r.default || r || []', + `export default ${genObjectFromRawEntries([ + ['entry', `() => [${globalStylesArray.map((_, i) => `style_${i}`).join(', ')}]`], + ...Object.entries(emitted).map(([key, value]) => [key, `() => import('./${this.getFileName(value)}').then(interopDefault)`]) as [string, string][] + ])}` ].join('\n') }) },