Skip to content

Commit 664f0d5

Browse files
committed
avoid invalidating root layout on every navigation
1 parent d4d4789 commit 664f0d5

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

apps/svelte.dev/src/routes/+layout.server.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,21 @@ const nav_links: NavigationLink[] = [
5151
}
5252
];
5353

54-
const sections: Record<string, string> = {
55-
docs: 'Docs',
56-
playground: 'Playground',
57-
blog: 'Blog',
58-
tutorial: 'Tutorial',
59-
search: 'Search'
60-
};
61-
62-
const banner: BannerData = {
63-
id: 'adventofsvelte2024',
64-
start: new Date('1 December, 2024 00:00:00 UTC'),
65-
end: new Date('25 December, 2024 23:59:59 UTC'),
66-
arrow: true,
67-
content: {
68-
lg: 'Twenty-four days, twenty-four features: Advent of Svelte 2024',
69-
sm: 'Advent of Svelte 2024'
70-
},
71-
href: '/blog/advent-of-svelte'
72-
};
73-
74-
export const load = async ({ url }) => {
75-
const nav_title = sections[url.pathname.split('/')[1]!] ?? '';
54+
// const banner: BannerData = {
55+
// id: 'adventofsvelte2024',
56+
// start: new Date('1 December, 2024 00:00:00 UTC'),
57+
// end: new Date('25 December, 2024 23:59:59 UTC'),
58+
// arrow: true,
59+
// content: {
60+
// lg: 'Twenty-four days, twenty-four features: Advent of Svelte 2024',
61+
// sm: 'Advent of Svelte 2024'
62+
// },
63+
// href: '/blog/advent-of-svelte'
64+
// };
7665

66+
export const load = async () => {
7767
return {
78-
nav_title,
79-
nav_links,
80-
banner
68+
nav_links
69+
// banner
8170
};
8271
};

apps/svelte.dev/src/routes/+layout.svelte

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import '@sveltejs/site-kit/styles/index.css';
33
import { browser, dev } from '$app/environment';
4-
import { page } from '$app/stores';
4+
import { page } from '$app/state';
55
import { Shell, Banner } from '@sveltejs/site-kit/components';
66
import { Nav } from '@sveltejs/site-kit/nav';
77
import { SearchBox } from '@sveltejs/site-kit/search';
@@ -28,19 +28,27 @@
2828
});
2929
3030
let { data, children: layout_children } = $props();
31+
32+
const sections: Record<string, string> = {
33+
docs: 'Docs',
34+
playground: 'Playground',
35+
blog: 'Blog',
36+
tutorial: 'Tutorial',
37+
search: 'Search'
38+
};
3139
</script>
3240

3341
<svelte:head>
34-
{#if !$page.route.id?.startsWith('/blog/')}
42+
{#if !page.route.id?.startsWith('/blog/')}
3543
<meta name="twitter:card" content="summary" />
3644
<meta name="twitter:image" content="https://svelte.dev/images/twitter-thumbnail.jpg" />
3745
<meta name="og:image" content="https://svelte.dev/images/twitter-thumbnail.jpg" />
3846
{/if}
3947
</svelte:head>
4048

41-
<Shell nav_visible={$page.route.id !== '/(authed)/playground/[id]/embed'}>
49+
<Shell nav_visible={page.route.id !== '/(authed)/playground/[id]/embed'}>
4250
{#snippet top_nav()}
43-
<Nav title={data.nav_title} links={data.nav_links} />
51+
<Nav title={sections[page.url.pathname.split('/')[1]!] ?? ''} links={data.nav_links} />
4452
{/snippet}
4553

4654
{#snippet children()}

packages/site-kit/src/global.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
declare global {
44
namespace App {
5-
interface PageData {
6-
nav_title: string;
7-
}
5+
interface PageData {}
86
}
97
}
108

0 commit comments

Comments
 (0)