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

Fix bug when checking schema properties for schemaChange #5426

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Component.prototype = {
// Check if we need to update schema.
if (this.schemaChangeKeys.length) {
for (key in attrValue) {
if (this.schema[key].schemaChange) {
if (key in this.schema && this.schema[key].schemaChange) {
mayNeedSchemaUpdate = true;
break;
}
Expand Down
66 changes: 66 additions & 0 deletions tests/core/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,72 @@ suite('Component', function () {
assert.equal(3, el.object3D.position.y);
assert.equal(3, el.object3D.position.z);
});

test('calls updateSchema when initializing component', function () {
let updateSchemaSpy = this.sinon.spy();
registerComponent('dummy', {
schema: {
type: {default: 'plane', schemaChange: true}
},
updateSchema: function () {
updateSchemaSpy();
}
});
el.hasLoaded = true;
el.setAttribute('dummy', {});
assert.ok(updateSchemaSpy.calledOnce);
});

test('updates schema when property with schemaChange is changed', function () {
let updateSchemaSpy = this.sinon.spy();
registerComponent('dummy', {
schema: {
type: {default: 'plane', schemaChange: true},
color: {default: 'blue'}
},
updateSchema: function () {
updateSchemaSpy();
}
});
el.hasLoaded = true;
el.setAttribute('dummy', {});
el.setAttribute('dummy', {type: 'box'});
assert.ok(updateSchemaSpy.calledTwice);
});

test('does not update schema when no property with schemaChange is changed', function () {
let updateSchemaSpy = this.sinon.spy();
registerComponent('dummy', {
schema: {
type: {default: 'plane', schemaChange: true},
color: {default: 'blue'}
},
updateSchema: function () {
updateSchemaSpy();
}
});
el.hasLoaded = true;
el.setAttribute('dummy', {});
el.setAttribute('dummy', {color: 'red'});
assert.ok(updateSchemaSpy.calledOnce);
});

test('ignores invalid properties when checking if schema needs to be updated', function () {
let updateSchemaSpy = this.sinon.spy();
registerComponent('dummy', {
schema: {
type: {default: 'plane', schemaChange: true},
color: {default: 'blue'}
},
updateSchema: function () {
updateSchemaSpy();
}
});
el.hasLoaded = true;
el.setAttribute('dummy', {});
el.setAttribute('dummy', {invalidProperty: 'should be ignored', color: 'red'});
assert.ok(updateSchemaSpy.calledOnce);
});
});

suite('resetProperty', function () {
Expand Down
Loading