Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guarantee that $page.route has the correct shape #8359

Merged
merged 3 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-feet-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Guarantee that `$page.route` has the correct shape
9 changes: 6 additions & 3 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export function create_client({ target, base }) {
);
return false;
}
} else if (navigation_result.props?.page?.status >= 400) {
} else if (/** @type {number} */ (navigation_result.props?.page?.status) >= 400) {
const updated = await stores.updated.check();
if (updated) {
await native_navigation(url);
Expand Down Expand Up @@ -369,7 +369,7 @@ export function create_client({ target, base }) {
const style = document.querySelector('style[data-sveltekit]');
if (style) style.remove();

page = result.props.page;
page = /** @type {import('types').Page} */ (result.props.page);

root = new Root({
target,
Expand Down Expand Up @@ -435,6 +435,7 @@ export function create_client({ target, base }) {
route
},
props: {
// @ts-ignore Somehow it's getting SvelteComponent and SvelteComponentDev mixed up
components: filtered.map((branch_node) => branch_node.node.component)
}
};
Expand Down Expand Up @@ -473,7 +474,9 @@ export function create_client({ target, base }) {
result.props.page = {
error,
params,
route,
route: {
id: route?.id ?? null
},
status,
url: new URL(url),
form: form ?? null,
Expand Down
10 changes: 8 additions & 2 deletions packages/kit/src/runtime/client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
preloadCode,
preloadData
} from '$app/navigation';
import { CSRPageNode, CSRPageNodeLoader, CSRRoute, TrailingSlash, Uses } from 'types';
import { SvelteComponent } from 'svelte';
import { CSRPageNode, CSRPageNodeLoader, CSRRoute, Page, TrailingSlash, Uses } from 'types';

export interface Client {
// public API, exposed via $app/navigation
Expand Down Expand Up @@ -58,7 +59,12 @@ export type NavigationRedirect = {
export type NavigationFinished = {
type: 'loaded';
state: NavigationState;
props: Record<string, any>;
props: {
components: Array<typeof SvelteComponent>;
page?: Page;
form?: Record<string, any> | null;
[key: `data_${number}`]: Record<string, any>;
};
};

export type BranchNode = {
Expand Down