-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Reactivity not applying to action parameters #7429
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 is the intended behavior. There's no invalidation of a top-level variable in the component that Svelte can see at compile time, and so nothing is invalidated. If you need to do something that is (effectively) the invalidation of variables not known until runtime, you can pass in a store to the action. |
Cool, but I am interested in why this can't be seen at compile time... My understanding is if you had code like this:
At compile time it sees the For actions, if you had:
Wouldn't the compiler be able to see the "foo" in just the same way, and add |
Top-level variables are invalidated when they are directly assigned to—it doesn't work if you modify them indirectly (eg. through another name/reference). Your |
Hmm, maybe this doesn't work like I think it does, even event handlers don't seem to be reactive in this way, i.e. https://svelte.dev/repl/769fa87bc8464fdaa7f56fcb8414a846?version=3.46.6 |
Ah I'm dumb, I was confusing upstream reactive dependencies with direct reactivity, which needs un unaliased lvalue, sorry for the noise. |
Describe the bug
Sorry if this is a dupe or expected behavior...
I know that reactivity isn't supposed to transcend function calls, so people add extra params to the function calls (needed or not) to indicate they should be reactive. It's just about the name of the variable being present at the original site. So here I have an example of an action that mutates a local state variable, and I was expecting reactivity to trigger based on my referencing the name of the variable in the
use:recordWidth={container}
part. See repl here:https://svelte.dev/repl/2128a5163144488285449cbf4514ffbf?version=3.46.6
I'd expect the see the width of the element printed out. If I interrogate the value later it is correct, it's just not triggering reactivity like I'd expect.
Reproduction
See above.
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: