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

Data from +layout.server.ts is null after navigating #6459

Closed
luhagel opened this issue Aug 31, 2022 · 7 comments · Fixed by #6778
Closed

Data from +layout.server.ts is null after navigating #6459

luhagel opened this issue Aug 31, 2022 · 7 comments · Fixed by #6778
Labels
bug Something isn't working
Milestone

Comments

@luhagel
Copy link

luhagel commented Aug 31, 2022

I mean the load({data}) in layout.ts, that should hold the data from layout.server.ts.

This still seems to be an issue, even if there is no need to rerun the server load, I'd still expect the data object to stay the same instead of becoming null after navigating

// +layout.server.ts

export const load: LayoutServerLoad = async ({ locals, url }) => {
	if (!locals.token) {
		throw redirect(302, `/login?${new URLSearchParams({ callBackUrl: url?.pathname ?? '/' }).toString()}`)
	}

	const jwt = decode<JWTPayload>(locals.token)
	const session = {
		user: {
			id: jwt['sub'],
			email: jwt['email']
		},
	}
	return {
		token: locals.token,
		settings: locals.appSettings,
		session: session
	}
}

//+layout.ts

export const load: LayoutLoad = async ({ data, url }) => {
	await loadTranslations(getDefaultLocale(), url.pathname) // keep this just before the `return`
	return {
		token: data.token,
		settings: data.settings,
		session: data.session
	}
}

Will error out after page change
Screenshot 2022-08-30 at 07 20 56

EDIT: Running on next.454

Originally posted by @luhagel in #6349 (comment)

@alialaa
Copy link

alialaa commented Aug 31, 2022

I also opened a similar issue in #6336 and it was supposedly fixed but I am still having the same problem.

@laxadev
Copy link

laxadev commented Aug 31, 2022

I have the same issue too. From time to time when I navigate on the site it returns null but if I hard refresh the site all is good.

@AlexRMU
Copy link

AlexRMU commented Sep 1, 2022

The same with using depends and invalidate

@mquandalle
Copy link

Minimal reproduction of the issue: https://stackblitz.com/edit/sveltejs-kit-template-default-qvjxq7?file=src/routes/+page.svelte

@AlexRMU
Copy link

AlexRMU commented Sep 3, 2022

@mquandalle
Copy link

I opened up a discussion on a API change that is related to this issue: #6570

@Rich-Harris Rich-Harris added the bug Something isn't working label Sep 6, 2022
@Rich-Harris Rich-Harris added this to the 1.0 milestone Sep 6, 2022
@ni-max
Copy link
Contributor

ni-max commented Sep 12, 2022

Minimal reproduction of the issue: https://stackblitz.com/edit/sveltejs-kit-template-default-qvjxq7?file=src/routes/+page.svelte

I encountered this bug today,
accessing url.pathname seems to be a workaround as of 1.0.0-next.480

--- page.server.js	2022-09-12
+++ page.server.js	2022-09-12
@@ -1,4 +1,5 @@
-export function load() {
+export function load({url}) {
+	url.pathname;
 	return {
 		textFromTheServer: `This text comes from the server \`load\` function.
       It should remain on screen when we stay on page (even if the client \`load\` is rerun when clicking ABC and DEF links below).`

Rich-Harris pushed a commit that referenced this issue Sep 14, 2022
* [fix] reuse server data while not reusing client load

Fixes #6459

* add back code that got lost during hickup

* fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
7 participants