-
-
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
Two-way binding for a component makes two updates in a reactive block if bind:value=<object>
#3075
Comments
I am having the same issue. Value changes twice when there is a two way binding in custom components. In my case, for example, I am having a custom component This doesn't happen when using the binding with a native component like |
I'm having the same problem, and in my use case it also causes an unnecessary network request. I made a REPL before I found this issue. |
Oh, I just figured out a workaround for my project, in case it helps someone. If you want the source of truth on the prop to come from the child component, then leave it undefined in the parent. Then, you can make the reactive variable have a condition on the presence of that variable. eg: <script>
let prop;
$: prop && console.log(prop);
</script>
<Child bind:prop/> Might not work for every use case but maybe that helps someone. |
This, at last, should be fixed in 3.32.2 - https://svelte.dev/repl/d4df9f70eb34430abde39f7e8d0cd1d1?version=3.32.2 - thanks @pushkine! |
I'm not sure if this is fixed yet – or maybe it's a different-but-similar bug that I found? I've modified the REPL such that the https://svelte.dev/repl/a72ad960202241f5af39a90337dafa9d?version=3.38.3 |
Primitive types and bindings in native
<input>
work fine. See REPL.I added
<svelte:options immutable={true}/>
and the problem has gone. However I see inconsistent behaviour for<Custom bind:value={object.prop}/>
and<input bind:value={object.prop}/>
whenimmutable
is false. Is this a bug?The text was updated successfully, but these errors were encountered: