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

getPropsData() sets propsData for all props regardless of attribute existence. collides with 'required' validation #140

Closed
djabor opened this issue Aug 8, 2018 · 3 comments
Labels

Comments

@djabor
Copy link

djabor commented Aug 8, 2018

Setting a required prop, but not setting the attribute on the HTML element:

expected behavior: setting { required: true } for a prop, should fail validation, in dev mode it should show a console.error.

actual behavior: required validation succeeds and collides with subsequent validations. e.g. asserting type.

propsData[propCamelCase] = propValue instanceof Attr

using the custom elements in a document, without the required [required:true] props results in a bypassed validation.

https://github.com/vuejs/vue/blob/81e1e47cabbd479e2a285f03120944f1efffe749/src/core/util/props.js#L28

is where vue checks whether propsdata property exists. since the properties exist with undefined value, absent is always false due to using this mechanism:

https://github.com/vuejs/vue/blob/653aac2c57d15f0e93a2c1cc7e6fad156658df19/src/shared/util.js#L139

as a result, the validation check:
https://github.com/vuejs/vue/blob/81e1e47cabbd479e2a285f03120944f1efffe749/src/core/util/props.js#L107
always fails to enter the condition.

suggested fix:

const propValue = element.attributes[name] || element[propCamelCase];
// ...
// ...
// ensure propsData is only set if `propsValue` exists.
if (propValue instanceof Attr) {
     propsData[propCamelCase] = convertAttributeValue(propValue.value, type)
} else if (typeof propValue !== 'undefined')
     propsData[propCamelCase] = propValue;
}
@djabor djabor changed the title getPropsData() sets propsData for all props regardless of existence. collides with require validation getPropsData() sets propsData for all props regardless of attribute existence. collides with require validation Aug 8, 2018
@djabor djabor changed the title getPropsData() sets propsData for all props regardless of attribute existence. collides with require validation getPropsData() sets propsData for all props regardless of attribute existence. collides with require validation Aug 8, 2018
@djabor djabor changed the title getPropsData() sets propsData for all props regardless of attribute existence. collides with require validation getPropsData() sets propsData for all props regardless of attribute existence. collides with 'required' validation Aug 8, 2018
@karol-f
Copy link
Owner

karol-f commented Aug 8, 2018

Thanks for detailed explanation, I will look at it soon.

@karol-f karol-f added the bug label Aug 8, 2018
karol-f added a commit that referenced this issue Aug 12, 2018
…attribute existence. collides with 'required' validation
@karol-f
Copy link
Owner

karol-f commented Aug 12, 2018

Fixed in [email protected] (https://github.com/karol-f/vue-custom-element/releases/tag/v3.2.5). Thanks for the issue!

@karol-f karol-f closed this as completed Aug 12, 2018
@djabor
Copy link
Author

djabor commented Aug 12, 2018

thanks, I hadn't had the time to debug it in depth, but I noticed that I missed a few more locations requiring fixes to this issue's end. I'll give it a spin later today! thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants