-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Incorrect "ownership invalid binding" error when using snippets to render children #14893
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
The fact that you can't reproduce in the playground is suspicious and unfortunately we can't know if it's a duplicate unless you provide an actual reproduction. My suggestion is to try to get to the bottom of it and reproduce it in the playground since this is purely runtime (doesn't involve hydration or SSR which is difficult to reproduce in the playground) so it might be something completely different. |
Sorry, I explained myself incorrectly: in the playground, I don't see in general any ownership error messages in console. Here is an example: clearly, the binding is incorrect, but there is no ownership warning anywhere: https://svelte.dev/playground/ebea059bfd2d4975a8edeff0e6e44198?version=5.16.1 However if you take the example and use it in a real project it will trigger warnings: the component "MyComponent" is mutating a value owned by its parent without a binding in place. So in svelte playground it's impossible to reproduce this bug because of limitations of svelte playground. I will take some time and prepare a repo anyway, I understand it's impossible to get triaged otherwise. |
That is not a mutation: if you pass an object and mutate one of the properties you do get a warning in the console. |
We are also experiencing this issue, we made sure that we have bind: on our Grandparent, Parent, and child components but it still gives out the warning. we are also using snippets. BUT when we removed the snippet and just use the actual html code, it now does NOT give us the warning |
Do you have a reproduction? |
We're still testing .. we're trying to create a new repository, but we are unable to create a reproduction... we'll go back thru our code and figure out what might be the cause... Is it possible for svelte compiler or for the warning to be more "specific" like, what state specifically is being changed by what component? |
You already have the information about which file is mutating state from which other component...I don't think we can pinpoint the exact line |
I created a separate repository and could not reproduce the issue; however on my private repository I really checked every single line and every single binding, and I have the issue. I think the issue exists but manifests itself only in particular situations. It will take some time to minimize my own repo to check at which point the issue disappears. |
Has anyone had any luck with this? I was also unable to reproduce the problem with both the Playground and a brand new project. I tried both SvelteKit and Svelte with Vite. For the record, my situation is likely quite unique due to my project being a browser extension with WXT and Svelte. I don't know how much that matters seeing others have the same problem. |
Rendering snippets with bind: values sometimes result in a warning See: sveltejs/svelte#14893
Previously we were doing stack-based retrieval of the owner, which while catching more cases was costly (performance-wise) and prone to errors (as shown by many issues over the months). This drastically simplifies the ownership validation - we now only do simple static analysis to check which props are mutated and wrap them with runtime checks to see if a binding was established. Besides making the implementation simpler and more performant, this also follows an insight we had over the months: Most people don't really know what to do with this warning when it's shown beyond very simple cases. Either it's not actionable because they don't really know how to fix it or they question if they should at all (in some cases rightfully so). Now that the warning is only shown in simple and easy-to-reason-about cases, it has a much better signal-to-noise-ratio and will hopefully guide people in the right direction early on (learn from the obvious cases to not write spaghetti code in more complex cases). closes #15532 closes #15210 closes #14893 closes #13607 closes #13139 closes #11861
Describe the bug
Issue: checking ownership of values does not "skip" intermediate components that render children using @render, when binding is used in their children from their parent.
Example: in a component in svelte5 have a structure like this:
where ChildComponent uses @render to render its children (that is the GrandChildComponent). In console I get a bogus warning: ownership_invalid_binding suggesting to create a binding between the main component and the ChildComponent. Which is impossible, as ChildComponent is a generic reusable component that renders a child. I also tried, just for the sake of it, to add statevar to the bindable properties of ChildComponent and bind it, and the problem is solved.
I wanted to reproduce it on svelte playground but unfortunately there I don't get ownership warnings.
Reproduction
Before spending time on a minimal reproduction I'd like to get the bug triaged, since it might be a dupe, or a "won't fix" situation and it takes time to create a separate repo just for reproduction. But I will do that immediately if this is a new bug report.
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: