Skip to content
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

Null prop value now interpreted as a value, rather than null, meaning the default isnt used. #3135

Closed
leeovery opened this issue Jun 22, 2016 · 6 comments

Comments

@leeovery
Copy link

leeovery commented Jun 22, 2016

Hi,

Vue.js version

1.0.25

Reproduction Link

http://jsfiddle.net/st5bak15/2/

This break occurred after upgrading to 1.0.25. It worked as (I) expect in 1.0.24 and below...

What's Happening?

Previously I was defining a prop value on a component as either a json object, or null, depending on whether it was defined or not.

In the case of the prop value being null, Vue would default to using the defined prop default from the component, rather than explicitly null.

However, now the opposite is happening. When null is sent in as the prop value, the prop value remains as null, rather than being recognised as null and then loading up the default value.

Not sure if this was an intended change or not but thought Id highlight it as it has broke my app.

Cheers
Lee

@simplesmiler
Copy link
Member

simplesmiler commented Jun 22, 2016

I think this was intentional. null is a special value, and should not be replaced with default. If you want default, then send in undefined.

/cc @phanan, I recall you mentioning it.

@leeovery
Copy link
Author

Thanks @simplesmiler. I wondered if that might have been the case. Gotta love breaking changes :)

Not sure how I would send in undefined. Currently I send in either a json_encoded php array, or null. I can change null to something else but how would I send in undefined? If I send as a string it fails as the prop expects an array. Plus it would compile as a string anyway, even if it didn't fail. I could send an empty array but then it obviously stays as an empty array and doesnt fallback to the default prop value.

I feel that null would have made more sense when bridging from php to js...

@simplesmiler
Copy link
Member

Something like :prop="undefined", just like you did with :prop="null".

@leeovery
Copy link
Author

Ok thank you. Seems it has to be explicitly set as opposed to being set from a php callback. Its being sent as a string in that latter case which is causing Vue to squawk. In the former (like your example above) it works fine and is recognised as JS undefined.

@phanan
Copy link
Member

phanan commented Jun 22, 2016

FYI, the previous misbehavior (treating null as undefined) was fixed in this commit: 4d4059b

@bichikim
Copy link

<myComponent :value="foo || undefined"/> :)

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

No branches or pull requests

4 participants