Skip to content

Data fetched in +layout.server.ts only loads after the initial render [SvelteKit/Svelte 5 (Runes)] #1753

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

Open
mitchuman opened this issue Aug 15, 2024 · 2 comments
Assignees

Comments

@mitchuman
Copy link

I've Converted the setup documented here to use Runes.

Screenshot 2024-08-14 at 10 25 29 PM

I've fetched data in a layout and a catch-all route server files, but only the catch-all route has the data pass to the .svelte file on the server.

Data fetched into the +layout.svelte only populates after first render.

Screen.Recording.2024-08-14.at.10.26.54.PM.mov

Notice the page loads with page data already rendered (the "Updated weekly..." copy), but the navigation content is initially empty.

My thought is, the useQuery function is not fully converted to Svelte 5 (Runes), but not sure if this is what's causing the layout data to load only after the initial render...

For reference, I have a repo/repro here

@mitchuman mitchuman changed the title svelte-loader to update for the upcoming Svelte 5 (Runes)? Data fetched in +layout.server.ts only loads after the initial render. [SvelteKit/Svelte 5 (Runes)] Aug 15, 2024
@mitchuman mitchuman changed the title Data fetched in +layout.server.ts only loads after the initial render. [SvelteKit/Svelte 5 (Runes)] Data fetched in +layout.server.ts only loads after the initial render [SvelteKit/Svelte 5 (Runes)] Aug 15, 2024
@rdunk rdunk self-assigned this Aug 19, 2024
@LouVerdun
Copy link

LouVerdun commented Nov 29, 2024

Hello @mitchuman, @rdunk, did you find a solution or a workaround to this issue? I'm having the same issue now, having me setup a static splash while the data is being fetched from the layout. I'm now calling my Global settings query in each page to make the data available in the layout.svelte file but that seems quite unintuitive and clearly hacky... Thank you very much in advance!

@LouVerdun
Copy link

LouVerdun commented Dec 3, 2024

Hi there, I'm allowing to answer my own question here. Taking the attached repo as a reference, the site data is not passed down to the layout.svelte file through layout.ts. layout.ts is only used to setPreviewing. So the data should be fetched in layout.server.ts, passed down to layout.ts along with preview. And then it can be directly used in layout.svelte. I don't know if that helps anyone but that actually how I found out how Svelte actually works ^^. I still can't get live previews to work though, if you have any idea on why the repo's setup doesn't work, I'll take it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants