You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
I'm exploring the standard svelte-sapper template and I want to add a button in the Nav component that will excute some login logic. I also want to separate the button's presentation and logic so I try to use slots for this. In the added component, Login.svelte:
<script>
let onclick;
onclick = function() {
window.alert('ALERT');
// Browser-specific Auth0 logic should go here
};
</script>
<div>
<slot onclick={onclick}></slot>
</div>
There are two issues here:
The code gets executed on server side before hydration (evidenced by a 500 error briefly shown on server route execution). After some research I see that this should be solved by simply checking for typeof window?
When I click the button I get (in the browser console):
What I'm trying to achieve is basically passing the event handler to a slot. Using recommendations in the docs for making a client-only component doesn't seem to work with slots (see below).
Attempts at solving
I read about making code execute on client only and as much as I dislike all the boilerplate, I tried to do that and apparently slots are not passed on to child components so that to my understanding doesn't work.