-
-
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
Cannot bind to stores from within a snippet #13076
Comments
Rather than passing arounds store, you should be passing in the value from the store into the snippet. This is because we can't create subscriptions inside the snippet – which is required when you reference a store with |
This might be a problem since the component that is calling the snippet is generic and only knows that it is a store and unaware of the shape of the data. I am recreating Superforms "componentization": https://superforms.rocks/components I have a component called |
I mean this is already the case with Svelte 4 slots, you cannot subscribe to a store inside the slot either. How did you do this before with Svelte 4? |
This is true. After I made this issue I attempted to do this in Svelte 4 and reached the same issue. Side note: I attempted to convert the $form store within SimpleForm to a rune with |
|
Interesting, it seems the only solution then is to pass the superform through the snippet --> into an inner component, and subscribe from there. |
It almost worked! But broke once I tried to target a nested property: Try here |
That's because the nested property isn't reactive? You need to use |
Yep, by design, as you stated. What is the reason for this difference? // title is reactive
let data = $state({title: “hello”}) vs. let dataStore = writable({title: “hello”})
// title is NOT reactive
let data = fromStore(dataStore) |
@pauldemarco I mean you can put state into a store, that's what I was demonstrating – to make the store deeply reactive. |
The goal at this point is to convert it into a deeply reactive rune so that I could bind to it within the snippet. |
@pauldemarco I get that, but if you convert it into a deeply reactive state, it won't propagate changes back up to the store again. The store itself needs to define this otherwise the deep state will only be local. |
I don’t have the ability to create the store — it is given to me by the Superform library. The hope was to convert into a rune that is completely 2-way bound to the store. It seems though this isn’t possible, ‘fromStore’ creates a rune with only top level reactivity, and does not propagate inner changes back to the store. I guess I would ask, is it not possible to have it just be fully reactive and stays completely in sync with the store? I can’t imagine, especially during the transition period from 4-5, that this wouldn’t be the intended operation everyone expects. |
@pauldemarco You'll need to rework things or get the upstream library to move over to Svelte 5. |
Naive question for @trueadm or any other Svelte master: Why the scope cannot be determined in the template? Isn't the template a valid place where to subscribe to stores? I wonder this because |
Describe the bug
I am getting this error when trying to access a store passed in via snippet parameter:
Reproduction
https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAA42QS2rDMBCGrzKoBdtg7K6T2PRxjLqLxJ4QEVkSo3FLEbp7keQ40G661Oh_zHxenKVCJ3bvXujjjGInXqwVteBvGx_uExWjqIUzC41xcnAjScv9oAeWszXE8LowGw1nMjMUTZufTbYW-0Ef2rtHH1a10aOS47XzZQVdD0eFxGXxFmc4AV8QTklYVCF1-QenpbXIMF6kmgh1acnYKsTPgVMY-Mc4SyPfrvoQF8ilvajFbCZ5ljiJHdOCod7uzpL_nq6QwW-r1NA0Tax2EKCDtIUrq_2gV0Qevkjy8aQQwgoq57eODSVKt9TRLJqRoNss5VP1G2JmA_5WuzJ6JtQT0h3RGlYlCNnUD_ovho_wA4i41NgKAgAA
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: