Skip to content
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

Merged
merged 4 commits into from
Oct 23, 2024

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Oct 23, 2024

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 the ctx which contained if we're in runes or not, meaning that they were not working correctly – so I had to fix them too.

Copy link

changeset-bot bot commented Oct 23, 2024

🦋 Changeset detected

Latest commit: 94e31a5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

@dummdidumm dummdidumm merged commit d621f59 into main Oct 23, 2024
7 checks passed
@dummdidumm dummdidumm deleted the derived-get-context branch October 23, 2024 18:38
@github-actions github-actions bot mentioned this pull request Oct 23, 2024
@mustafa0x mustafa0x mentioned this pull request Oct 25, 2024
1 task
@JonathonRP
Copy link

I should be able to use $derived(getContext(...)) without error of getContext needs to be in component initialization code, correct?

@trueadm
Copy link
Contributor Author

trueadm commented Dec 17, 2024

@JonathonRP Where is your $derived located? Do you have a REPL?

@JonathonRP
Copy link

JonathonRP commented Dec 17, 2024

@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

@JonathonRP
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$derived loses context for getContext
4 participants