Skip to content

Commit

Permalink
Don't stringify properties with undefined values in flushToDOM (#5549)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrxz authored Jun 27, 2024
1 parent f6fe0c3 commit 230d4f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ module.exports.stringifyProperties = function (propData, schema) {
value = stringifyProperty(propValue, propDefinition);
if (!propDefinition) { warn('Unknown component property: ' + propName); }
}
stringifiedData[propName] = value;
if (value !== undefined) {
stringifiedData[propName] = value;
}
}
return stringifiedData;
};
Expand Down
13 changes: 13 additions & 0 deletions tests/core/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,19 @@ suite('Component', function () {
el.components.dummy.flushToDOM();
assert.equal(HTMLElement.prototype.getAttribute.call(el, 'dummy'), 'isDurrr: false');
});

test('omits cleared properties', function () {
var el = document.createElement('a-entity');
registerComponent('dummy', {
schema: {name: {type: 'string'}}
});
el.setAttribute('dummy', 'name', 'John');
el.components.dummy.flushToDOM();
assert.equal(HTMLElement.prototype.getAttribute.call(el, 'dummy'), 'name: John');
el.setAttribute('dummy', 'name', '');
el.components.dummy.flushToDOM();
assert.equal(HTMLElement.prototype.getAttribute.call(el, 'dummy'), '');
});
});

suite('play', function () {
Expand Down

0 comments on commit 230d4f7

Please sign in to comment.