-
-
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
Missing "ownership_invalid_mutation" when using snippets ? #14145
Comments
Just make the passed in Working with docs on |
Thank you, that's not what I meant. The warning routine is "dumb" and think, that I am manipulating data in App. But this is not the case. |
Svelte tracks where the data is coming from, because the child is still accessing it from the parent by reference. You're still mutating the parent's data. Since the snippets are defined in the parent and therefore, it seems, svelte is ok with them mutating the data in the same component. if you moved the snippets to the child component, you will get a warning on both buttons now, since now the snippets are defined on the child and are mutating the parent's data: both warn In the example where you're using a "callback" function, the function is still defined in the parent component and is still mutating the data from the same component, so no warning. So, based on the reasons above, the runtime warning is valid and consistent. I don't think the warning shows up in production builds but I'd say it's a good practice to indicate it for code readability if nothing else. |
Thank you @Leonidaz for the throrough explanation - closing as this works as designed. |
Describe the bug
I'm not sure... is this by design or not?
My example: LINK
I have a component, where I modify a received property.
One time it's directly inside component.
and another time it's inside snipped (which is also used in Component)
It has basically the same onclick - It will modify received data inside Component.
But only gray button produce a warning (missing ownership_invalid_mutation).
This do not happen, if I click snipped button (colored).
As I understand, we should not mutate received data.
Instead, we should use callback functions.
Right?
But... wow, I wish, we could officialy use such code... how beautiful is that to avoid callbacks?
We need clarity here... Perhaps quick response.
Otherwise, I don't know how to write right code now...
same code, but with callbacks:
LINK
Reproduction
see above
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: