Skip to content

Commit d561656

Browse files
committed
Merge branch 'main' into version-3
2 parents f76d7d9 + 5c38e51 commit d561656

7 files changed

Lines changed: 30 additions & 10 deletions

File tree

.changeset/clear-deer-doubt.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: ensure CSS URL references are absolute when `paths.relative` is `false`

packages/kit/src/exports/vite/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ function kit({ svelte_config }) {
12321232
let new_config;
12331233

12341234
if (is_build) {
1235-
const prefix = `${kit.appDir}/immutable`;
1235+
const app_immutable = `${kit.appDir}/immutable`;
12361236

12371237
/** @type {Record<string, string>} */
12381238
const server_input = {
@@ -1313,9 +1313,9 @@ function kit({ svelte_config }) {
13131313

13141314
/** @type {string} */
13151315
const base = (kit.paths.assets || kit.paths.base) + '/';
1316-
const root_to_assets = prefix + '/assets/';
1316+
const root_to_assets = app_immutable + '/assets/';
13171317
const assets_to_root =
1318-
prefix
1318+
app_immutable
13191319
.split('/')
13201320
.map(() => '..')
13211321
.join('/') + '/../';
@@ -1338,7 +1338,7 @@ function kit({ svelte_config }) {
13381338
rolldownOptions: {
13391339
output: {
13401340
name: `__sveltekit_${version_hash}.app`,
1341-
assetFileNames: `${prefix}/assets/[name].[hash][extname]`,
1341+
assetFileNames: `${app_immutable}/assets/[name].[hash][extname]`,
13421342
hoistTransitiveImports: false,
13431343
sourcemapIgnoreList
13441344
},
@@ -1391,8 +1391,8 @@ function kit({ svelte_config }) {
13911391
input: inline ? client_input['bundle'] : client_input,
13921392
output: {
13931393
format: inline ? 'iife' : 'esm',
1394-
entryFileNames: `${prefix}/[name].[hash].js`,
1395-
chunkFileNames: `${prefix}/chunks/[hash].js`,
1394+
entryFileNames: `${app_immutable}/[name].[hash].js`,
1395+
chunkFileNames: `${app_immutable}/chunks/[hash].js`,
13961396
codeSplitting:
13971397
svelte_config.kit.output.bundleStrategy === 'split' ? undefined : false
13981398
},
@@ -1428,6 +1428,11 @@ function kit({ svelte_config }) {
14281428
return { relative };
14291429
}
14301430

1431+
if (!relative) return;
1432+
1433+
// ensure assets loaded by CSS files are loaded relative to the
1434+
// CSS file rather than the default of relative to the root
1435+
14311436
// _app/immutable/assets files
14321437
if (filename.startsWith(root_to_assets)) {
14331438
return `./${filename.slice(root_to_assets.length)}`;

packages/kit/test/apps/options/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
"check": "svelte-kit sync -c vite.custom.config.js && tsc && svelte-check --config vite.custom.config.js",
1111
"test": "pnpm test:dev && pnpm test:build",
1212
"test:dev": "DEV=true playwright test && DEV=true PATHS_ASSETS=https://cdn.example.com/stuff playwright test",
13-
"test:build": "playwright test && PATHS_ASSETS=https://cdn.example.com/stuff playwright test",
13+
"test:paths-relative:build": "playwright test",
14+
"test:paths-absolute:build": "PATHS_RELATIVE=false playwright test",
15+
"test:paths-assets:build": "PATHS_ASSETS=https://cdn.example.com/stuff playwright test",
16+
"test:build": "pnpm test:paths-relative:build && pnpm test:paths-absolute:build && pnpm test:paths-assets:build",
1417
"test:unit": "vitest run --config vite.custom.config.js",
1518
"test:server-side-route-resolution:dev": "rm -rf test/errors.json && DEV=true ROUTER_RESOLUTION=server playwright test",
1619
"test:server-side-route-resolution:build": "rm -rf test/errors.json && ROUTER_RESOLUTION=server playwright test"

packages/kit/test/apps/options/playwright.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export default defineConfig({
99
command: process.env.DEV ? `pnpm dev` : `pnpm build && pnpm preview`,
1010
env: {
1111
ROUTER_RESOLUTION: process.env.ROUTER_RESOLUTION ?? 'client',
12-
PATHS_ASSETS: process.env.PATHS_ASSETS ?? ''
12+
PATHS_ASSETS: process.env.PATHS_ASSETS ?? '',
13+
PATHS_RELATIVE: process.env.PATHS_RELATIVE ?? 'true'
1314
}
1415
}
1516
});
File renamed without changes.

packages/kit/test/apps/options/test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { test } from '../../../utils.js';
55

66
test.describe.configure({ mode: 'parallel' });
77

8-
test.skip(!!process.env.PATHS_ASSETS);
8+
test.skip(!!process.env.PATHS_ASSETS || process.env.PATHS_RELATIVE === 'false');
99

1010
test.describe('CSP', () => {
1111
test('blocks script from external site', async ({ page, start_server }) => {

packages/kit/test/apps/options/vite.custom.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@ const config = {
4444
paths: {
4545
base: '/path-base',
4646
// @ts-expect-error our env var string can't match the https template literal
47-
assets: process.env.PATHS_ASSETS || ''
47+
assets: process.env.PATHS_ASSETS,
48+
relative: process.env.PATHS_RELATIVE !== 'false'
4849
},
4950
env: {
5051
dir: './env-dir'
5152
},
5253
router: {
5354
resolution: /** @type {'client' | 'server'} */ (process.env.ROUTER_RESOLUTION) || 'client'
55+
},
56+
typescript: {
57+
config(config) {
58+
config.include.push('../vite.custom.config.js', '../playwright.config.js');
59+
}
5460
}
5561
})
5662
],

0 commit comments

Comments
 (0)