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

Layout data is cleared when url is used in +layout.ts #6336

Closed
alialaa opened this issue Aug 27, 2022 · 1 comment · Fixed by #6352
Closed

Layout data is cleared when url is used in +layout.ts #6336

alialaa opened this issue Aug 27, 2022 · 1 comment · Fixed by #6352
Labels
bug Something isn't working

Comments

@alialaa
Copy link

alialaa commented Aug 27, 2022

Describe the bug

I was having some simple redirect logic in my application in +layout.ts:

export const load = async ({ data, url }) => {
	const { user } = data || {};
	if (user && url.pathname === '/login') {
		throw redirect(302, '/');
	}
	if (!user && url.pathname !== '/login') {
		throw redirect(302, '/login');
	}
	return {
		user
	};
};

After updating to @sveltejs/[email protected], the app was fully reloading when navigating instead of client side routing. After some investigation I found out that using url in +layout causes the data passed from +layout.server to be cleared.

In the example below I am just logging url.pathname in +layout and displaying the data in the Home page. When navigating from and the back to the home page; the data is cleared. That won't happen if console.log(url.pathname) is removed from +layout.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-bdr4bj?file=src/routes/+layout.js

Logs

No response

System Info

System:
    OS: macOS 12.1
    CPU: (8) arm64 Apple M1
    Memory: 1.63 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.16.0 - /usr/local/bin/node
    Yarn: 1.22.11 - ~/.npm-global/bin/yarn
    npm: 8.11.0 - /usr/local/bin/npm
    Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 104.0.5112.101
    Safari: 15.2
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.66 
    @sveltejs/kit: ^1.0.0-next.423 => 1.0.0-next.444 
    svelte: ^3.44.0 => 3.49.0 
    vite: ^3.0.0 => 3.0.9

Severity

blocking an upgrade

Additional Information

No response

@dummdidumm dummdidumm added the bug Something isn't working label Aug 28, 2022
@alialaa
Copy link
Author

alialaa commented Aug 29, 2022

I believe this issue still exists in 1.0.0-next.446. I updated the demo above with 1.0.0-next.446 and the data is still being cleared.

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
Development

Successfully merging a pull request may close this issue.

2 participants