From 03c6bab9b206654fee094187abb847050aa46016 Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Thu, 28 Nov 2024 16:07:26 +0800 Subject: [PATCH 1/4] don't copy ssr css --- packages/kit/src/exports/vite/index.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index e6521e979560..1a79f37bc888 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -815,10 +815,22 @@ async function kit({ svelte_config }) { }) ); - copy( - `${out}/server/${kit.appDir}/immutable/assets`, - `${out}/client/${kit.appDir}/immutable/assets` - ); + // we do not want to copy the unused server stylesheets generated by + // Vite's `build.ssrEmitAssets` option + /** @type {string[]} */ + const ssr_stylesheets = []; + for (const key in server_manifest) { + if (server_manifest[key].css) { + ssr_stylesheets.push(...server_manifest[key].css); + } + } + const ssr_stylesheets_set = new Set(ssr_stylesheets); + + const assets_path = `${kit.appDir}/immutable/assets`; + + copy(`${out}/server/${assets_path}`, `${out}/client/${assets_path}`, { + filter: (basename) => !ssr_stylesheets_set.has(`${assets_path}/${basename}`) + }); /** @type {import('vite').Manifest} */ const client_manifest = JSON.parse(read(`${out}/client/${vite_config.build.manifest}`)); From 0b16cdb4939450109c6cea3afe1260931fd8ec81 Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Thu, 28 Nov 2024 16:08:52 +0800 Subject: [PATCH 2/4] changeset --- .changeset/twelve-gifts-wait.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/twelve-gifts-wait.md diff --git a/.changeset/twelve-gifts-wait.md b/.changeset/twelve-gifts-wait.md new file mode 100644 index 000000000000..210f869417a2 --- /dev/null +++ b/.changeset/twelve-gifts-wait.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: avoid copying SSR stylesheets to client assets From 8b24a7015d799df31bdabcce95c4e63af2d140f7 Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Thu, 28 Nov 2024 16:16:04 +0800 Subject: [PATCH 3/4] fix lint error --- packages/kit/src/exports/vite/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 1a79f37bc888..419e507dd37e 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -820,8 +820,9 @@ async function kit({ svelte_config }) { /** @type {string[]} */ const ssr_stylesheets = []; for (const key in server_manifest) { - if (server_manifest[key].css) { - ssr_stylesheets.push(...server_manifest[key].css); + const stylesheets = server_manifest[key].css; + if (stylesheets) { + ssr_stylesheets.push(...stylesheets); } } const ssr_stylesheets_set = new Set(ssr_stylesheets); From df52a4eed06395b62934933e8ab7d620df957e30 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:32:04 +0100 Subject: [PATCH 4/4] Update packages/kit/src/exports/vite/index.js --- packages/kit/src/exports/vite/index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 419e507dd37e..8a52c04d1feb 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -817,20 +817,19 @@ async function kit({ svelte_config }) { // we do not want to copy the unused server stylesheets generated by // Vite's `build.ssrEmitAssets` option - /** @type {string[]} */ - const ssr_stylesheets = []; + /** @type {Set} */ + const ssr_stylesheets = new Set(); for (const key in server_manifest) { - const stylesheets = server_manifest[key].css; - if (stylesheets) { - ssr_stylesheets.push(...stylesheets); + const stylesheets = server_manifest[key].css ?? []; + for (const stylesheet of stylesheets) { + ssr_stylesheets.add(stylesheet); } } - const ssr_stylesheets_set = new Set(ssr_stylesheets); const assets_path = `${kit.appDir}/immutable/assets`; copy(`${out}/server/${assets_path}`, `${out}/client/${assets_path}`, { - filter: (basename) => !ssr_stylesheets_set.has(`${assets_path}/${basename}`) + filter: (basename) => !ssr_stylesheets.has(`${assets_path}/${basename}`) }); /** @type {import('vite').Manifest} */