Skip to content

Commit 5ad3e2e

Browse files
committed
fix(#140): getPropsData() sets propsData for all props regardless of attribute existence. collides with 'required' validation
1 parent dc29a75 commit 5ad3e2e

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

demo/components/DemoBasic-component.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
<script>
3535
export default {
3636
props: {
37-
prop1: {},
37+
prop1: {
38+
required: true
39+
},
3840
prop2: {},
3941
prop3: {},
4042
stringProp: {

src/utils/createVueInstance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function createVueInstance(element, Vue, componentDefinition, pro
4646
reactiveProps() {
4747
const reactivePropsList = {};
4848
props.camelCase.forEach((prop) => {
49-
reactivePropsList[prop] = this[prop];
49+
typeof this[prop] !== 'undefined' && (reactivePropsList[prop] = this[prop]);
5050
});
5151

5252
return reactivePropsList;

src/utils/props.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function convertAttributeValue(value, overrideType) {
1414
const valueParsed = parseFloat(propsValue, 10);
1515
const isNumber = !isNaN(valueParsed) && isFinite(propsValue) && (typeof propsValue === 'string' && !propsValue.match(/^0+[^.]\d*$/g));
1616

17-
if (overrideType && overrideType !== Boolean) {
17+
if (overrideType && overrideType !== Boolean && typeof propsValue !== overrideType) { // eslint-disable-line valid-typeof
1818
propsValue = overrideType(value);
1919
} else if (isBoolean || overrideType === Boolean) {
2020
propsValue = propsValue === '' ? true : propsValue === 'true';
@@ -122,9 +122,12 @@ export function getPropsData(element, componentDefinition, props) {
122122
type = props.types[propCamelCase];
123123
}
124124

125-
propsData[propCamelCase] = propValue instanceof Attr
126-
? convertAttributeValue(propValue.value, type)
127-
: propValue;
125+
// ensure propsData is only set if `propsValue` exists.
126+
if (propValue instanceof Attr) {
127+
propsData[propCamelCase] = convertAttributeValue(propValue.value, type);
128+
} else if (typeof propValue !== 'undefined') {
129+
propsData[propCamelCase] = propValue;
130+
}
128131
});
129132

130133
return propsData;

0 commit comments

Comments
 (0)