It would be great if I could send props to the _layout.svelte.
Scenario:
I have different pages with different headers, configurable from the backend. Those headers need to be in the _layout.svelte file because they have a transition animation. The page info is loaded inside the [slug].svelte but I need a way to communicatie the header to the layout file. I now have a workaround where I load the page in the _layout & on the page and using a store to communicate to the layout, but this is a very hacky solution (maybe someone has a better solution?).
Maybe something like this would be possible to send props to the layout file, like svelte:head (or something different):
<svelte:props name={value} />
This is more of a support question and should be asked in Discord or over at Stack Overflow.
But the recommended way to communicate with layouts from components would be using the Context API
He did ask on Discord already, please don't flood everywhere with your question until you get an answer puresoul. This can be safely closed.
I did not ask this before, sorry for the inconvenience, I will ask on Discord from now on.
The Context API is not a solution to this problem, I always get null from getContext in the _layout, because the setContext in the page is called to late & it's not being rendered when setContext is called.
Adding a bind inside the @sapper/internal/App.svelte fixes this issue, and also work with ssr, so maybe adding a layoutProp export, which gets bind to the layout, would be an idea?
But I got another idea. It would be great if you could implement your own App.svelte, like so:
import * as sapper from '@sapper/app';
import App from './App.svelte'
sapper.start({
target: document.querySelector('#sapper'),
app: App
});
The functionality would be the same as it is. But when you specify a app component, it will be rendered, and you are responsible to implement the layout yourself. It would fix another problem for me and gives the developer a lot of flexibility.
I hope this is something which is in line with the road sapper is heading, because it's something I will be encounter more often, if I am going to use sapper, in feature projects. I'm really pleased with sapper/svelte and I hope I'm able to use it more often in the feature. Maybe I can implement it myself and send a merge request? But I would like to know your thoughts.
Context is the standard way to enable communication between a parent and its slots, and a Layout is exactly that, a parent with slots. We don't need additional APIs to do this.
Context works great from parent to child. But I can't make this work from child to parent, on initialization: https://svelte.dev/repl/6a4d90034ac94055b5548aa299ac6604?version=3.6.7
The strange thing is, the log is working but it is not being rendered.
Take it to one of the support channels. I've already explained that github issues are not the place for support requests.
I think this is a bug, don't you?
No.
Can you explain why? The variable someValue is being changed, but not rendered to screen.
Removing the first callback, fixes this issue, but it's not work with SSR.
You need to come to one of our support channels and we will help you. We do not deal with support issues in github issues as it makes things very difficult to track and generates a lot of noise. You can ask a question at stackoverflow with the svelte or sapper tag, or you can come and chat to us in discord.
@pngwn I meant can you explain why you think this is not a bug? I got the feeling you did not check the link I provided. In my example the variable inside the layout is changed but it's not being rendered. This is a bug! I understand it's a bug of svelte and not sapper, so if you prefer me to post it there, I will.
If you think there is a bug then please file an issue in the relevant repository with a minimal reproduction and the necessary steps to reproduce.