-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat: allow usage of getContext() within $derived runes #13830
Conversation
🦋 Changeset detectedLatest commit: 94e31a5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js
Outdated
Show resolved
Hide resolved
I should be able to use $derived(getContext(...)) without error of |
@JonathonRP Where is your |
@trueadm let me see if I can make repl. I could be doing something wrong but I have a $derived that calls a function that accesses context with hasContext and/or getContext in a function and uses the from store to get current. again I'll see if I can make a repl. if it helps it only happens during hmr, it's not an issue on startup or refresh it seems - using sveltekit |
@trueadm this is what I was able to do, it doesn't produce the error in the client console but it's very close to what I am doing - https://stackblitz.com/edit/sveltejs-kit-template-default-n4ftuvxm?file=README.md I can share a screen shot and repo too if that helps more? |
Closes #13493.
This PR allows the usage of
getContext()
inside$derived
runes. Previously, you could use it, but only on init and not updates – and this inconsistency was unnecessary. We can make it work just like we do in other places.One interested thing came about from this change – a bunch of our existing tests broke because they incorrectly did not pass
is_runes
internally as the derived never had access to thectx
which contained if we're in runes or not, meaning that they were not working correctly – so I had to fix them too.