Skip to content

Commit 180fa34

Browse files
authored
fix: ignore non-entry-point CSS files during inlining (#13395)
fixes #13068 (comment)
1 parent 3dec396 commit 180fa34

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

.changeset/shaggy-ravens-unite.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: ignore non-entry-point CSS files during inlining

packages/kit/src/exports/vite/build/build_server.js

+5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ export function build_server_nodes(out, kit, manifest_data, server_manifest, cli
4747
css.filter(asset => client_stylesheets.has(asset.fileName))
4848
.forEach((asset) => {
4949
if (asset.source.length < kit.inlineStyleThreshold) {
50+
// We know that the names for entry points are numbers.
5051
const [index] = basename(asset.fileName).split('.');
52+
// There can also be other CSS files from shared components
53+
// for example, which we need to ignore here.
54+
if (isNaN(+index)) return;
55+
5156
const server_stylesheet = server_stylesheets.get(+index);
5257
const file = `${out}/server/stylesheets/${index}.js`;
5358

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<p>
2+
This component is imported in multiple pages and therefore its CSS lands in a separate CSS chunk
3+
</p>
4+
5+
<style>
6+
p {
7+
color: blue;
8+
}
9+
</style>

packages/kit/test/apps/options/source/pages/inline-assets/+page.svelte

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<script>
2+
import SharedCSS from '$lib/SharedCSS.svelte';
23
import '@fontsource/libre-barcode-128-text';
34
</script>
45

5-
<p>Hello world!</p>
6+
<p>
7+
Test that the fontsource is referenced correctly, while the shared CSS in SharedCSS doesn't cause
8+
problems
9+
</p>
10+
<SharedCSS />
611

712
<style>
813
p {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<script>
22
import { resolveRoute } from '$app/paths';
3+
import SharedCss from '$lib/SharedCSS.svelte';
34
</script>
45

6+
<SharedCss />
57
<a data-id="target" href={resolveRoute('/resolve-route/[foo]', { foo: 'resolved' })}>click me</a>

0 commit comments

Comments
 (0)