Skip to content

Commit c3f918e

Browse files
authored
fix: make route resolution imports root-relative if path.relative option is false (#13412)
It is necessary to adhere to this setting because rewrites that SvelteKit cannot see may otherwise lead to incorrect relative paths. Example: - route resolution request to _app/route.js - rewrite to _app/route/foo.js - SvelteKit only sees the later, returning a relative `import('../immutable/...`) which is wrong, because the actual relative path would be `import('./immutable/...)`
1 parent 2c6e8dc commit c3f918e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changeset/sharp-games-rule.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: make route resolution imports root-relative if `paths.relative` option is `false`

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { base, assets } from '__sveltekit/paths';
1+
import { base, assets, relative } from '__sveltekit/paths';
22
import { text } from '../../../exports/index.js';
33
import { s } from '../../../utils/misc.js';
44
import { exec } from '../../../utils/routing.js';
@@ -47,6 +47,10 @@ function create_client_import(import_path, url) {
4747
return `import('${assets}/${import_path}')`;
4848
}
4949

50+
if (!relative) {
51+
return `import('${base}/${import_path}')`;
52+
}
53+
5054
// Else we make them relative to the server-side route resolution request
5155
// to support IPFS, the internet archive, etc.
5256
let path = get_relative_path(url.pathname, `${base}/${import_path}`);

0 commit comments

Comments
 (0)