-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
injected objects are reactive (despite documentation saying the opposite) #5913
Comments
Hm, indeed. Thanks for reporting this! It seems #5204 introduced this, but I don't think this was intended. @yyx990803 I think this is a regression from the original, intended behaviour of |
thanks for reporting this! |
I'm glad I found this, I was pulling my hair off. Is this the same that is happening to me? https://jsfiddle.net/50wL7mdz/41229/ look how updating childObj.msg in component also updates someObj.msg in parent T.T |
Personally I considered this change as a feature more than a bug. |
@rayrutjes the injected properties themselves were left unreactive pretty much for the reason OP provided: So you can inject arbitrary objects, inlcuding complicated ones, in the background and have them left untouched. If you need reactivity, just pass down an already reactive object - best of both worlds. ;) |
@LinusBorg |
@LinusBorg I think that makes sense. Wondering how this will affect our existing code base ;) |
@Kingwl Could you make a PR to revert this behaviour? |
@LinusBorg i'm going to try it tomorrow... |
Version
2.3.3
Reproduction link
https://jsfiddle.net/50wL7mdz/41000/
Steps to reproduce
Provide (from parent component) an object with a pre-existing key. Inject that object into child component. Either console.log the object to see that it is reactive, or modify the value of the pre-existing key to see that the value also changes on screen automatically.
What is expected?
According to vue's documentation, injected objects are not reactive: "Note: the provide and inject bindings are NOT reactive.". The value should not change on the screen after 3 seconds, and console.log should not display the word Getter when logging the injected object.
What is actually happening?
The injected object is reactive, and so the message changes on screen after 3 seconds, and console.log'ging the object shows it is reactive (displays the word Getter)
I use inject to inject commonly used libraries in objects, like moment, which I can then use in the templates to display nicely formatted dates. If the entire moment library object becomes reactive, then this will probably cause an unnecessary performance hit to the browser when using the moment library.
The text was updated successfully, but these errors were encountered: