From 230d4f7724ce4b62560a21e1ab0ec022241ed3de Mon Sep 17 00:00:00 2001 From: Noeri Huisman <8823461+mrxz@users.noreply.github.com> Date: Thu, 27 Jun 2024 21:17:11 +0200 Subject: [PATCH] Don't stringify properties with undefined values in flushToDOM (#5549) --- src/core/schema.js | 4 +++- tests/core/component.test.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/schema.js b/src/core/schema.js index 905a60b1ec4..103e211993a 100644 --- a/src/core/schema.js +++ b/src/core/schema.js @@ -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; }; diff --git a/tests/core/component.test.js b/tests/core/component.test.js index 8331a05e078..045a59c894d 100644 --- a/tests/core/component.test.js +++ b/tests/core/component.test.js @@ -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 () {