diff --git a/.changeset/tall-impalas-report.md b/.changeset/tall-impalas-report.md new file mode 100644 index 000000000000..1cabd2e5ae62 --- /dev/null +++ b/.changeset/tall-impalas-report.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: always include ``, even for stylesheets excluded from Link headers diff --git a/packages/kit/src/runtime/server/page/render.js b/packages/kit/src/runtime/server/page/render.js index 5a64f8326a63..da2659fc4557 100644 --- a/packages/kit/src/runtime/server/page/render.js +++ b/packages/kit/src/runtime/server/page/render.js @@ -235,20 +235,20 @@ export async function render_response({ for (const dep of stylesheets) { const path = prefixed(dep); - if (resolve_opts.preload({ type: 'css', path })) { - const attributes = ['rel="stylesheet"']; - - if (inline_styles.has(dep)) { - // don't load stylesheets that are already inlined - // include them in disabled state so that Vite can detect them and doesn't try to add them - attributes.push('disabled', 'media="(max-width: 0)"'); - } else { + const attributes = ['rel="stylesheet"']; + + if (inline_styles.has(dep)) { + // don't load stylesheets that are already inlined + // include them in disabled state so that Vite can detect them and doesn't try to add them + attributes.push('disabled', 'media="(max-width: 0)"'); + } else { + if (resolve_opts.preload({ type: 'css', path })) { const preload_atts = ['rel="preload"', 'as="style"']; link_header_preloads.add(`<${encodeURI(path)}>; ${preload_atts.join(';')}; nopush`); } - - head += `\n\t\t`; } + + head += `\n\t\t`; } for (const dep of fonts) { diff --git a/packages/kit/test/apps/options/source/hooks.server.js b/packages/kit/test/apps/options/source/hooks.server.js index e69de29bb2d1..0ca3568e9c0c 100644 --- a/packages/kit/test/apps/options/source/hooks.server.js +++ b/packages/kit/test/apps/options/source/hooks.server.js @@ -0,0 +1,8 @@ +/** @type {import('@sveltejs/kit').Handle} */ +export function handle({ event, resolve }) { + return resolve(event, { + // this allows us to check that is still added + // to the DOM even if they're not included by `preload` + preload: ({ type }) => type !== 'css' + }); +}