-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
False positive ownership_invalid_binding
?
#13607
Comments
Cloning the repo locally i can't seem to reproduce...what are the reproduction steps? |
This one is probably a duplicate of 13423 |
So, I was able to reproduce it, but I'm not sure if it's the same reproduction as in this issue. Here's a REPL This happens when state is stored in a separate file from where it was declared/instantiated. I hope REPL will make it clear enough. I wonder if it's actually a 'legit' svelte coding pattern... |
Thanks for the REPL repro @someone2080 ! That's exactly when it appears to be happening when it shouldn't. |
Hey team, are there any plans to allow users to shut some of these warnings up? I understand they only run during |
Isn't one of the intended benefits of Svelte 5 runes that you can store state in any non-svelte component and use it elsewhere? If this isn't the intended behavior, what would be the correct way to distribute components that take state as props and modify them? |
@coryvirok Yes, you are right. I'm using this method, too. Runes in this mode are very powerful; they remind me of SwiftUI state management. The issue here is that this also opened a rabbit hole. I'm not a JS expert, but this warning was meant to prevent us from doing crazy things like in this REPL, we can do this thanks to the fact that JS objects are passed by reference. Now, Svelte team has to find a way to track down where and how this Rune was declared and issue a valid warning, which to me looks like a huge lift. I wonder if it's possible to remove this restriction altogether and use $bindable only for simple types if necessary (kinda crazy idea though). |
I am seeing the same issue with what I think is a reasonable design pattern. I have 2 relevant components: 1 that produces something and 1 that modifies it.
I thought the "svelte" way to do this would be to bind variables through all of the components. I should be able to fix this with some callbacks or a moderate restructure of the data, but it seemed to me like the bind solution should work. Edit: Its not clear to me how to have this kind of behavior without seeing this warning. |
@kpwelsh Yeah, that looks pretty reasonable. It's a false positive. |
i am using Tauri and getting this bug even when using this example from svelte playground. For some reason, there is no this warnings in firefox 134.0 and chromium 131.0. |
Are you sure you are literally only using that example? I think we need an actual reproduction |
I rechecked it and it happens only in tauri when the code is hot reloaded. If you change any code fragment and open the console after hot-reloading, you will get these warnings. And it seems there are no problems with a full restart. It seems to have something to do with tauri, because I can't get this behavior in browsers |
This has nothing to do with Tauri. It is a general svelte issue when you bind to an object, and then perform a hot reload on the component that has the bindable props. I have made a minimal repro here: https://github.com/F2/svelte-bug-ownership_invalid_mutation In the video here, you can see that entering text into the textbox does not throw any warnings. But after a hot reload, it starts throwing warnings. svelte-bug.mp4 |
I'm also struggling with false |
Happens to me too. I have created state in a component and chained it down with |
I'm getting this too, In my case it's because I have 3 components using bind, in some cases I wan't to bind to selectedValue on grandParent, in other cases I do not wan't to. Is this bad practice? the code runs as I would expect. <!-- +page.svelte -->
<script>
import GrandParent from '...';
</script>
<GrandParent /> <!-- GrandParent.svelte -->
<script>
import Parent from '...';
let {
selectedValue = $bindable()
} = $props();
</script>
<Parent bind:selectedValue /> <!-- Parent.svelte -->
<script>
import Child from '...';
let {
selectedValue = $bindable()
} = $props();
</script>
<Child bind:selectedValue /> <!-- Child -->
<script>
let {
selectedValue = $bindable()
} = $props();
</script>
<!-- Do something & mutate selectedValue --> |
You all can ignore this message if you wish by putting the following above the component that is doing the "invalid binding" <!-- svelte-ignore ownership_invalid_binding -->
<Something bind:somethingElse /> |
Describe the bug
I'm getting the following message, telling me to consider
bind:
between the two components. However, I am, in fact, binding between the two.Reproduction
https://svelte.dev/playground/c27c1016f1f2423489568d9fb2271921?version=5.2.5
Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: