Skip to content

Commit

Permalink
fix: make route resolution imports root-relative if path.relative o…
Browse files Browse the repository at this point in the history
…ption 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/...)`
  • Loading branch information
dummdidumm authored Feb 3, 2025
1 parent 2c6e8dc commit c3f918e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sharp-games-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: make route resolution imports root-relative if `paths.relative` option is `false`
6 changes: 5 additions & 1 deletion packages/kit/src/runtime/server/page/server_routing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { base, assets } from '__sveltekit/paths';
import { base, assets, relative } from '__sveltekit/paths';
import { text } from '../../../exports/index.js';
import { s } from '../../../utils/misc.js';
import { exec } from '../../../utils/routing.js';
Expand Down Expand Up @@ -47,6 +47,10 @@ function create_client_import(import_path, url) {
return `import('${assets}/${import_path}')`;
}

if (!relative) {
return `import('${base}/${import_path}')`;
}

// Else we make them relative to the server-side route resolution request
// to support IPFS, the internet archive, etc.
let path = get_relative_path(url.pathname, `${base}/${import_path}`);
Expand Down

0 comments on commit c3f918e

Please sign in to comment.