Describe the problem
In Classic SvelteKit, you can get all page data anywhere in your app through the page variable (previously $page). This is specifically available under page.data for data that is returned.
You cannot do this with a Remote Function query(). The data is NOT available globally, although it can be cached in multiple components.
Imagine this scenario:
- Layout (Breadcrumb) - no await
- Users (await getUserList())
- Jonathan (await getUser())
- Posts (await getPostList())
- My Post 1 (await getPostById(params.id))
- Comment 2 (await getCommentById(params.comment_id))
- About -- no await
And I want to display a simple breadcrumb:
Home -> Users -> Jonathan
Home -> Posts -> SvelteKit Remote Functions Tips
Home -> About
I can set the Breadcrumbs in the +layout.svelte file, BUT I am actually querying the data on the page itself... (username, page title, comment title, or no query at all, etc)
This CAN be solved using +page.server.ts for the query, and setting the crumb data in the +layout.svelte with page.data.
However, this is impossible to work using Remote Function queries.
Describe the proposed solution
Either:
- Expose the query data globally in
page.query... like page.query.myFunc...
- Expose the query data globally in
query or query.data... like query.myFunc...
Alternatives considered
- Use
+page.server.ts instead of query() to set the data using page.data... this can mess up your query refreshes etc, since it DOES NOT use query() and has you revert back to old paradigms.
- Use
hooks.server.ts to replace your entire HTML with something like %crumbs% that you query in query() and set like event.locals.query... etc... basically just hack the HTML right before render.
Importance
would make my life easier
Additional Information
Basically I can't use Remote Functions without it, since I have shared data in a layout.
Describe the problem
In Classic SvelteKit, you can get all page data anywhere in your app through the
pagevariable (previously$page). This is specifically available underpage.datafor data that is returned.You cannot do this with a Remote Function
query(). The data is NOT available globally, although it can be cached in multiple components.Imagine this scenario:
And I want to display a simple breadcrumb:
I can set the Breadcrumbs in the
+layout.sveltefile, BUT I am actually querying the data on the page itself... (username, page title, comment title, or no query at all, etc)This CAN be solved using
+page.server.tsfor the query, and setting the crumb data in the+layout.sveltewithpage.data.However, this is impossible to work using Remote Function queries.
Describe the proposed solution
Either:
page.query... likepage.query.myFunc...queryorquery.data... likequery.myFunc...Alternatives considered
+page.server.tsinstead ofquery()to set the data usingpage.data... this can mess up your query refreshes etc, since it DOES NOT usequery()and has you revert back to old paradigms.hooks.server.tsto replace your entire HTML with something like%crumbs%that you query inquery()and set likeevent.locals.query... etc... basically just hack the HTML right before render.Importance
would make my life easier
Additional Information
Basically I can't use Remote Functions without it, since I have shared data in a layout.