-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
getContext is undefined when called inside an element attribute. #7549
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
Comments
This would be an issue with Svelte itself, though it's unclear whether it's supposed to be one. Did Svelte ever guarantee expressions in the template happen during component initialization? The problem here appears to be that hydration isn't considered part of component initialization, which is why this works in SSR and the repl. It may be possible to change this cleanly, but I'm not sure if there would be other implications. |
We don't make that guarantee. It's the SSR behaviour that's wrong, in fact, though I haven't looked into how straightforward that would be to change |
I was thinking that this should probably be throwing an exception in both DOM and SSR mode, and it sounds like Rich is leaning in that same direction. We already have a function in |
closed via #11061 |
(or rather, this works as expected in Svelte 5 — not certain if this was ever fixed in 4 or below) |
Describe the bug
I have some text put into the context of a page. When reading it with
getContext
in a child component into the href of a link, the value isundefined
.The SSR handles it as expected but in the client it becomes
undefined
(only during hydration I think, not sure).Note that it is only undefined when called inside an href or other html attribute. When called as part of some text it is the expected value.
Reproduction
https://github.com/schurhammer/sveltekit-context-bug
Logs
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: