Repository navigation
breaking: remove leading / from AssetPath and Path - #16430
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/9956b0a3f9a410f71f28ed94e6dd9deff8a51cb4Open in |
🦋 Changeset detectedLatest commit: 9956b0a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…lash-prefixed pathnames because `resolve_route` is always called even for relative (non route-ID) inputs.
This commit fixes the issue reported at packages/kit/src/runtime/app/paths/server.js:24
## Bug
In `packages/kit/src/runtime/app/paths/server.js`, `resolve(id, params)` unconditionally calls `resolve_route(id, params ?? {})`, regardless of whether `id` starts with `/`.
`resolve_route` → `get_route_segments` does `route.slice(1)`:
```js
export function get_route_segments(route) {
return route.slice(1).split('/').filter(affects_path);
}
```
That `slice(1)` assumes the input is a route ID with a leading slash. When a plain pathname without a leading `/` is passed, the first character is silently dropped:
* `resolve_route('favicon.png', {})` → `/avicon.png`
* `resolve_route('about/us', {})` → `/bout/us`
* `resolve_route('/about', {})` → `/about` (correct)
Because this PR makes `AssetPath`/`Path` relative (no leading `/`), `resolve` now regularly receives non-slash inputs. This is especially impactful for `asset()`: in the default config `assets === base === ''`, so `asset('favicon.png')` calls `resolve('favicon.png')` and returns the corrupted `/avicon.png`.
The client implementation (`client.js`) is correct — it only calls `resolve_route` for `/`-prefixed route IDs and otherwise returns `base + pathname_prefix + '/' + args[0]`. The server version was missing the equivalent branch.
## Fix
Mirror the client's branching in the server `resolve`:
```js
let resolved;
if (id[0] === '/') {
if (id.includes('[') && !params) {
throw new Error(`Missing params for dynamic route ID
```
The existing `relative`/`base` handling continues to operate on `resolved`, so no other behavior changes. Now `asset('favicon.png')` resolves to `/favicon.png` (or the appropriate relative/base-prefixed form) instead of `/avicon.png`.
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <[email protected]>
… the resolved URL for static route IDs with no params, diverging from the client.
This commit fixes the issue reported at packages/kit/src/runtime/app/paths/server.js:34
## Bug
In `packages/kit/src/runtime/app/paths/server.js`, the `/`-prefixed branch was changed to:
```js
resolved = params ? resolve_route(id, params) : id;
```
When `params` is falsy (i.e. a static route ID passed with no params), this skips `resolve_route` entirely and uses the raw route `id`. But `resolve_route` → `get_route_segments` → `affects_path` also strips layout **group** segments matching `/^([^)]+)$/` (e.g. `(app)`, `(marketing)`), not just dynamic params.
### Concrete triggers
- `resolve('/(app)/dashboard')` returns `/(app)/dashboard` (literal parens in the URL) instead of `/dashboard`.
- `resolve('/(marketing)')` returns `/(marketing)` instead of `/`.
`resolve_route('/(app)/dashboard', {})` correctly returns `/dashboard`, confirming the divergence.
### Client/server parity
The client implementation (`client.js`) always calls `resolve_route(args[0], args[1] ?? {})` for `/`-prefixed inputs, so it correctly strips groups. The server change caused a mismatch: any static route inside a layout group would render broken links on the server.
## Fix
Restore unconditional group-stripping by always calling `resolve_route`, matching the client:
```js
resolved = resolve_route(id, params ?? {});
```
This handles both static routes with group segments and dynamic routes, and restores client/server parity.
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Rich-Harris <[email protected]>
Co-authored-by: Tee Ming <[email protected]>
This PR is 16430. Did you mean another issue? Also, the test type check is erroring because we can no longer do the |
commented
Jul 20, 2026
|
Yep, I meant #16425. The check failure is annoying as I'd got rid of the red squigglies locally with |
Yet, resolve() still takes a It is also very weird that if you resolve a Even worse, for simple routes you can use both, yet the migrator removes the leading
Maybe, but what about The SK2 version might have been confusing to those who used the advanced functionality. The SK3 version, while technically superior, is confusing to those who don't know about base URL. In case you're wondering why am I using Anyway, what's the rush with requiring everyone to remove SK2-style pathnames from their |
commented
Aug 20, 2026
|
@nickolay if you want to discuss this please open an issue! Merged PRs are not a good place to talk 😄 |
While working on #16372 I had a realisation that we shouldn't prefix
AssetandPathnamestrings with a/. It makes no sense — these are intended to be relative to the base path, and so having them be root-relative (/favicon.pnginstead offavicon.png) is wrong.This change means
Pathnameis the wrong name, since it wrongly implies a root-relativeurl.pathname. As well as removing the leading slash this PR renamesPathnametoPath, andAssettoAssetPath. (This allows future us to add a newAssettype containingpath: AssetPath, and possibly other stuff liketypeandsize.)There are practical benefits to removing the leading slash:
$app/manifestmodule #16372, we're adding an$app/manifestmodule withimmutableandassetsexports. The latter is an array of objects with apathproperty — rather than typing it asstring, we can type it asAssetPath. But if it had a leading slash then it would be unsuitable for its main purpose, which is for use withcache.add(path)inside a service worker. We can either make it base-path-relative (as this PR proposes) or root-relative (i.e./my-basepath/favicon.png) which is inherently less portable.pathelements in theprerenderedarray asPathrather thanstringresolve(path)andresolve(route_id), both type-wise and at runtime. At the moment they're sort of smushed together awkwardlyI also think that
asset('favicon.png')is just nicer to look at thanasset('/favicon.png')which is either weird or pointless depending on whether there's a configuredbase.Anyway: this is all somewhat independent of the
$app/manifeststuff so I figured it deserved its own PR.Closes #16425, by tightening up the type of
AssetPath(nostring & {}).Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits