Skip to content

chore #7070: warn properties that starts with $ or _ #7089

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

Closed
wants to merge 2 commits into from
Closed

chore #7070: warn properties that starts with $ or _ #7089

wants to merge 2 commits into from

Conversation

guieiras-dev
Copy link

close #7070

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:
As the docs says:

Properties that start with _ or $ will not be proxied on the Vue instance because they may conflict with Vue’s internal properties and API methods. You will have to access them as vm.$data._property.`

But, this is a little bit hidden during development. It would be better if a warn could be raised to show developer that the data property will not be proxied on the Vue instance.

@@ -141,7 +141,14 @@ function initData (vm: Component) {
`Use prop default value instead.`,
vm
)
} else if (!isReserved(key)) {
} else if (isReserved(key)) {
warn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warn must be shown only in development mode (process.env.NODE_ENV !== production)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@guieiras-dev
Copy link
Author

@posva How about this broken spec? And, as you said on the issue, isn't a little bit risky to proceed with this change as some users/plugins uses internally this kind of data?

@posva
Copy link
Member

posva commented Nov 21, 2017

The broken test is using $foo and btw, is wrong because it should ready $foo from this.$data and not from this but it doesn't change anything having undefined or {} as the injected value.

I think I went too fast saying we could safely add a warning for this, sorry about that.
If users want to add properties to data that start with $ or _ they're free to do so, they only need to know that in order to access them, they have to use this.$data
I don't have any better idea that just drop this 🙁
@chrisvfritz @sdras @LinusBorg do you have any feedback on how to improve this in case you have seen people falling under this caveat?

@guieiras-dev
Copy link
Author

@posva I was willing to contribute and I didn’t think about the consequences or how it could impact users. I’m sorry 😕.

Well, I think we can close this. Thanks for your review and the discussion.

@posva
Copy link
Member

posva commented Nov 21, 2017

No worries, as I said, I should have paid more attention 🙂

@posva
Copy link
Member

posva commented Nov 23, 2017

Let's close this for the moment

@posva posva closed this Nov 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn when a data property name starts with $ or _
3 participants