+layout.server.ts load re-runs on every navigation
See original GitHub issueDescribe the bug
Layout load
function runs on every navigation
Reproduction
Log to console when layout load function is executed and it happens on every navigation.
import type { LayoutServerLoad } from './$types'
export const load: LayoutServerLoad = async ({ }) => {
console.log('load /layout')
return {
name: 'My Site'
}
}
Logs
No response
System Info
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.64
@sveltejs/kit: next => 1.0.0-next.415
svelte: ^3.44.0 => 3.49.0
vite: ^3.0.0 => 3.0.8
Severity
blocking an upgrade
Additional Information
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Loading data • Docs • SvelteKit
A load function in a +page.js file runs both on the server and in the browser. ... +layout.svelte component above it, has access...
Read more >Sveltekit question: How to force loads to rerun for a page.server
Anyway i can force the layout to rerrun the load function? +page.server.ts import { redirect, type Cookies } from '@sveltejs/kit'; ...
Read more >Understanding Next.js routeChangeStart and router events
Next.js routeChangeStart and other router events make it possible for us to listen to events regarding navigations from one page to another.
Read more >Angular Breadcrumbs with Complex Routing and Navigation
Refreshing the current browser screen exactly repeats the existing activated route and URL but it does cause the problem of losing the component ......
Read more >AngularJS to Angular concepts: Quick reference
The *ngFor directive in Angular is like the ng-repeat directive in AngularJS. It repeats the associated DOM element for each item in the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
An argument against posting data back to the server is that we may want to introduce the ability to send non-JSONable values from the server:
It’s likely that we’d achieve that with https://github.com/rich-harris/devalue, which is only safe to use when sending data from the server to the client, not the other way around.
This Remix issue asking for loaders to use superjson has 37 👍 votes — it’s definitely not an unheard of requirement to include things like
Date
objects etc.Another case that JSON can’t handle is this, if the referential equality matters (which it would in a
<select bind:value>
for example):We don’t plan on using superjson, because devalue is faster, produces smaller output, and doesn’t force you to add a not-that-tiny client to deserialize on the client. But it does mean the data can only safely go one way. (Though we decided that sending data back to the server to simulate statefulness is a terrible idea anyway.)
(Re cache aware server push — the logic is on the wrong side. The server doesn’t need to know what the client has, because the client is going to tell it. All the server has to do is tell the client ‘this blob of data will be invalidated if
params.foo
changes’ or whatever.)