[breaking] replace routeId with route.id - #7450
Conversation
🦋 Changeset detectedLatest commit: 85d15e1 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 |
|
Is there anything else we foresee living in Whatever we do, for consistency I'd be in favor of having |
|
|
|
The site is failing to deploy because a code snippet in the docs references |
|
I made that change for export interface RequestHandler<
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>
> {
- (event: RequestEvent<Params>): MaybePromise<Response>;
+ (event: RequestEvent<Params> & { route: { id: string } }): MaybePromise<Response>;
}...then it works, but this is what I get if I hover over Not totally ideal. Do we need to come up with a new type that extends |
|
I thought this, too, but in some cases the root layout is loaded but without a route - for example when an infinite redirect loop is detected, or in case of a 404 - many ugh-vibes on this PR 😅 |
|
Ah crap, you're right — will revert the last commit. What if we went the generic route though, and made // .svelte-kit/types/src/routes/blog/$types.d.ts
export type PageLoad<...> = Kit.Load<..., OutputData, 'blog'>;
export type LayoutLoad<...> = Kit.Load<..., OutputData, 'blog' | 'blog/[slug]'>;Or is it misleading for the route object to exist when no route matched? |
|
Funny how we go through the same thought process independently. I asked myself the same question, and came to the conclusion that it's weird. Then again, all of this is weird, so we need to choose something that is the least weird while being easy enough to use. After having implemented this, part of me thinks |
|
And just as I'd come around to I think parity with
Yeah, I think the main use case is where you want some special case logic in a layout ('require the user to be logged in, unless the current |
|
I like |
| Params extends Partial<Record<string, string>> = Partial<Record<string, string>>, | ||
| OutputData extends Record<string, any> | void = Record<string, any> | void | ||
| OutputData extends Record<string, any> | void = Record<string, any> | void, | ||
| RouteId extends string | null = string | null |
There was a problem hiding this comment.
do we need the overhead of that interface on the action interfaces? Actions can only be used on pages, so routeId can only be one thing, so it's useless to use it, so probably noone does that, so we probably can just type this as string on RequestEvent
There was a problem hiding this comment.
Is there any real drawback? It's contrived but you could imagine someone doing this sort of thing, where some_shared_logic is picky about the second argument:
export const actions = {
blah: ({ request, route }) => {
some_shared_logic(request, route.id);
}
};|
Does that mean this also closes #6167? |
|
no, because that relates to |
|
Ok that was a bit of a faff but it will now correctly identify the dependency on /** @type {import('./$types').LayoutServerLoad} */
export function load({ route }) {
return { route };
}.,..and the same goes for |
…error page (#16381) After an error page renders, `current.route` is `null` (`load_root_error_page` stores `route: null` in the navigation state). The next navigation computes ```js const route_changed = current.route ? route.id !== current.route.id : false; ``` so the route counts as unchanged no matter where the user goes next. A root layout server load that tracked `route` is then skipped as fresh, and its data from before the error page renders on the new page. The new test's failing assertion on `version-3` shows the layout still claiming the previous route: ``` Expected: "/b" Received: "/a" ``` A missing `current.route` now counts as changed. On a first-ever navigation the flag is irrelevant, the node has no previous data to reuse anyway, so the only behavior change is the conservative refetch after error pages. The interaction was never designed. `route: null` came in #6552 to give `beforeNavigate` a value meaning "no matched route", and the guard came two months later in #7450 with route tracking itself, mirroring the adjacent `url_changed` null-guard. Neither discussed the error-page case. The test lives in the no-ssr app. Its root layout gains a server load returning `route.id`, the navigation's data request is intercepted with a 500 to produce the error page, and the follow-up navigation must show the new route id. The app's root `+layout.server.js` was an empty file, shipped by #11354 so its 404-loop test has a server load node in dev; giving it a real load keeps that trigger intact. Found while reviewing #16380, which mirrors this computation for the error page itself and carries the same one-line fix. --- ### Please don't delete this checklist! Before submitting the PR, please make sure you do the following: - [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs - [x] This message body should clearly illustrate what problems it solves. - [x] Ideally, include a test that fails without this PR but passes with it. ### Tests - [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check` ### Changesets - [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpm changeset` and following the prompts. Changesets that add features should be `minor` and those that fix bugs should be `patch`. Please prefix changeset messages with `feat:`, `fix:`, or `chore:`. ### Edits - [x] Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.


Closes #6980
Draft, because the tracking part is missing, and I'm not sure yet if we want to replace routeId in all places (like
$page.routeId)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. All changesets should bepatchuntil SvelteKit 1.0