-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
method named _update breaks component creation #6312
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
Vue itself uses underscore prefixes for internal methods. It's not advised you do so. |
PRs to add warnings that check the methods names are welcome I guess but, yeah, don't name methods with a starting underscore |
I didn't note that in the docs. I think it's unreasonable to expect people to have to respect naming strategies for methods, however, I understand it may not be so simple to make that change. I'll make a PR to add some warnings, and to make some notes in the documentation. |
@posva I believe similar PRs has existed before to add warning, but it turned out adding warning isn't easy. Vue adds methods one by one so it is hard to tell which word is internal. |
Damn, I didn't think it will be hard 🙁 |
@posva I'm still unfamiliar with the Vue codebase, but Symbols seem like a great way to mitigate this issue entirely. The other idea, though it's a breaking change, is to simply namespace the methods into As for updating the docs. PR here: vuejs/v2.vuejs.org#1072 I didn't really see a good place to add a note about naming methods in the guide, perhaps that deserves it's own heading, but I'm still trying to understand the codebase so I'd rather not write a guide to something I don't completely understand. |
@posva @HerringtonDarkholme @JustinBeaudry I might be misunderstanding, but would it not be possible to provide a warning here, if |
@chrisvfritz I was trying something like that locally this morning to see if that would work and it seems to. Instead of trying to warn against collisions against specific names, just warning about method names with |
@chrisvfritz The problem is some library will use prefixed method names to hide implementation. |
@HerringtonDarkholme But prefixed names shouldn't be used, due to the possible namespace collisions. It seems unreasonable to have to find every internal method used and only warn when a method conflicts with that. IMO It's either warn on every prefixed method name (it is just a warning after all) or namespace methods. |
@HerringtonDarkholme I agree with @JustinBeaudry in this case. It sounds like we all suggest not to use any underscore-prefixed datum/prop/computed/method names, because we can't guarantee that Vue won't conflict with them in the future. That means these plugins could already break at any moment, including in a patch release. I think it'd be better to have a one-time "soft break" with a warning that suggests an alternate strategy. Maybe the Then for any property registration, we could just display a warning if |
As a slight aside for private methods specifically, taking advantage of JS scoping might make more sense. For example: export default {
...
}
function myPrivateFunc (vm) { ... } |
@chrisvfritz Agree. Introducing a new naming pattern is good enough before we can safely use |
We cannot say it's just a warning. Introducing a new naming method convention will make a lot of library creators have warnings and fill the console for people using those plugins, making it very difficult to debug. Furthermore, more people will come and complain and create issues for nothing not only on Vue's repository but also on plugins' Even if Vue add methods one by one, we can create a static list of methods names that shouldn't be used, can't we? |
Unfortunately, we can't create a static list of all private property names that might be used in the future. And maintaining that list would be a pain, easily falling out of sync.
Not necessarily. We could start by introducing a new config (e.g. Once plugin authors have been trained, we could include a softer warning by default, e.g. with: console.warn(new Error(...)) That way:
In the future, Thoughts? |
It looks like a huge amount of work for very little benefit 😰 From my pov, a note on the docs is the best option. When using an |
I have reproduced this with the |
@posva I agree that right now, the problem is relatively small - at least as far as we can measure, since overriding private properties can produce difficult-to-diagnose errors, or worse, subtle bugs that don't even produce an error. Since it's difficult to track down and report, it might remain a largely invisible problem. And the longer we wait on something like this, the more plugins will exist and the more conflicts will arise, both with Vue and between plugins/mixins. I feel like we can wait until it's a bigger problem, but it's guaranteed to keep growing with Vue's popularity and it'll just be even more work at that point. @JustinBeaudry Yes, we'll have to warn about all top-level properties: data, props, computed properties, and methods. |
I still think that a more pragmatic way will be to document it because if people have built plugins that work, they've probably got around that naming restriction already. I really think we're trying to solve a problem that doesn't exist. What may happen in the future is that new users trying to create plugins face the issue and find out about this thread and end up fixing it in a couple of hours max |
@posva It sounds like your primary concern is just whether it's worth the effort. Is that accurate? If so, I think most of the work towards an ESLint rule is already done and I wouldn't mind writing the optional warnings behind the config flag. As a dev-only feature, it also wouldn't add to the weight of the production build. Does that sound acceptable, as a place to start? |
@chrisvfritz No, no, that's not my main concern 😆 |
@posva What impact on the development experience are you trying to avoid? If it's behind a config flag, wouldn't it only affect the experience for those who care about future compatibility? And always only in a positive way? I think hiding this important warning behind a compatibility flag is more likely to make people angry than offering them a chance to take a few minutes to prevent their apps from breaking in the future. 😄 I see this as similar to many security issues. We use SSL, even though a user's credentials probably won't be stolen. We're eliminating an especially ugly scenario, despite a relatively low likelihood of occurrence. And in both cases, it's an easy fix that you only have to make once. If an entire Vue app could break at any time, in a way that would be difficult to diagnose or possibly even detect, do you not feel that's worth a couple minutes to fix, even if it probably won't happen? |
By development experience, I also mean that most of the time it has an impact on performance. That wasn't clear, sorry. But this really depends on when does the check happen. |
Ah, I see. Since the check only happens on initialization and we're already iterating over each property for other checks, the impact should be minimal. |
Version
2.4.2
Reproduction link
[Method]
https://jsfiddle.net/50wL7mdz/52180/
and
[Computed]
https://jsfiddle.net/7d2aytsL/
Steps to reproduce
_update
method or computed property on a custom componentTypeError
What is expected?
An method called
_update
is a perfectly reasonable name for a method and/or computed property, and should not be throwing simply based on it's naming.What is actually happening?
I have yet to dig in further but for some reason the
vnode
object loses it's reference when having this method or computed name.The text was updated successfully, but these errors were encountered: