Skip to content

Commit fbe4fe7

Browse files
authored
always include <link rel="stylesheet"> even if excluded from Link headers - closes #8238 (#9255)
1 parent 3124296 commit fbe4fe7

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

.changeset/tall-impalas-report.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: always include `<link rel="stylesheet">`, even for stylesheets excluded from Link headers

packages/kit/src/runtime/server/page/render.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,20 @@ export async function render_response({
235235
for (const dep of stylesheets) {
236236
const path = prefixed(dep);
237237

238-
if (resolve_opts.preload({ type: 'css', path })) {
239-
const attributes = ['rel="stylesheet"'];
240-
241-
if (inline_styles.has(dep)) {
242-
// don't load stylesheets that are already inlined
243-
// include them in disabled state so that Vite can detect them and doesn't try to add them
244-
attributes.push('disabled', 'media="(max-width: 0)"');
245-
} else {
238+
const attributes = ['rel="stylesheet"'];
239+
240+
if (inline_styles.has(dep)) {
241+
// don't load stylesheets that are already inlined
242+
// include them in disabled state so that Vite can detect them and doesn't try to add them
243+
attributes.push('disabled', 'media="(max-width: 0)"');
244+
} else {
245+
if (resolve_opts.preload({ type: 'css', path })) {
246246
const preload_atts = ['rel="preload"', 'as="style"'];
247247
link_header_preloads.add(`<${encodeURI(path)}>; ${preload_atts.join(';')}; nopush`);
248248
}
249-
250-
head += `\n\t\t<link href="${path}" ${attributes.join(' ')}>`;
251249
}
250+
251+
head += `\n\t\t<link href="${path}" ${attributes.join(' ')}>`;
252252
}
253253

254254
for (const dep of fonts) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('@sveltejs/kit').Handle} */
2+
export function handle({ event, resolve }) {
3+
return resolve(event, {
4+
// this allows us to check that <link rel="stylesheet"> is still added
5+
// to the DOM even if they're not included by `preload`
6+
preload: ({ type }) => type !== 'css'
7+
});
8+
}

0 commit comments

Comments
 (0)