mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +00:00
fix(nuxt): in dev, don't link css
files with ?inline
query (#25822)
This commit is contained in:
parent
06352e350d
commit
e817655c14
@ -13,7 +13,7 @@ import { appendResponseHeader, createError, getQuery, getResponseStatus, getResp
|
||||
import devalue from '@nuxt/devalue'
|
||||
import { stringify, uneval } from 'devalue'
|
||||
import destr from 'destr'
|
||||
import { joinURL, withoutTrailingSlash } from 'ufo'
|
||||
import { getQuery as getURLQuery, joinURL, withoutTrailingSlash } from 'ufo'
|
||||
import { renderToString as _renderToString } from 'vue/server-renderer'
|
||||
import { hash } from 'ohash'
|
||||
import { renderSSRHead } from '@unhead/ssr'
|
||||
@ -392,6 +392,14 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
|
||||
const link = []
|
||||
for (const style in styles) {
|
||||
const resource = styles[style]
|
||||
// Do not add links to resources that are inlined (vite v5+)
|
||||
if (import.meta.dev && 'inline' in getURLQuery(resource.file)) {
|
||||
continue
|
||||
}
|
||||
// Add CSS links in <head> for CSS files
|
||||
// - in production
|
||||
// - in dev mode when not rendering an island
|
||||
// - in dev mode when rendering an island and the file has scoped styles and is not a page
|
||||
if (!import.meta.dev || !isRenderingIsland || (resource.file.includes('scoped') && !resource.file.includes('pages/'))) {
|
||||
link.push({ rel: 'stylesheet', href: renderer.rendererContext.buildAssetsURL(resource.file) })
|
||||
}
|
||||
|
@ -1414,6 +1414,15 @@ describe('automatically keyed composables', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe.runIf(isDev() && !isWebpack)('css links', () => {
|
||||
it('should not inject links to CSS files that are inlined', async () => {
|
||||
const html = await $fetch('/inline-only-css')
|
||||
expect(html).toContain('--inline-only')
|
||||
expect(html).not.toContain('inline-only.css')
|
||||
expect(html).toContain('assets/plugin.css')
|
||||
})
|
||||
})
|
||||
|
||||
describe.skipIf(isDev() || isWebpack)('inlining component styles', () => {
|
||||
const inlinedCSS = [
|
||||
'{--plugin:"plugin"}', // CSS imported ambiently in JS/TS
|
||||
|
3
test/fixtures/basic/assets/inline-only.css
vendored
Normal file
3
test/fixtures/basic/assets/inline-only.css
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
:root {
|
||||
--inline-only: 'inline-only';
|
||||
}
|
8
test/fixtures/basic/pages/inline-only-css.vue
vendored
Normal file
8
test/fixtures/basic/pages/inline-only-css.vue
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import css from '~/assets/inline-only.css?inline'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<pre>{{ css }}</pre>
|
||||
</template>
|
||||
|
Loading…
Reference in New Issue
Block a user