Skip to content
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
predicted from developers (#351).

### Fixed
- Explicitly setting `reflect` to `false` now works. Previously, setting this
explicitly (versus omitting entirely) would cause a runtime error (#354).
- Custom element constructors are no longer invoked during template analysis.
Previously, the internal computation and caching of a `DocumentFragment` would
cause custom element’s constructors to run. Now, an inert document is used at
Expand Down
15 changes: 15 additions & 0 deletions test/test-reflected-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class TestElement extends XElement {
initial: false,
reflect: true,
},
explicitlyNotReflected: {
type: Boolean,
reflect: false,
},
};
}
static template(html) {
Expand Down Expand Up @@ -104,3 +108,14 @@ it('does not reflect next false value (Boolean)', async () => {
await Promise.resolve();
assert(el.hasAttribute('boolean-property-true'));
});

// Setting “reflect: false” explicitly should behave the same as omitting it.
// See https://github.com/Netflix/x-element/issues/353.
it('does not error when reflect is explicitly set to false', async () => {
const el = document.createElement('test-element');
document.body.append(el);
el.explicitlyNotReflected = true;
await Promise.resolve();
assert(el.explicitlyNotReflected === true);
assert(el.hasAttribute('explicitly-not-reflected') === false);
});
2 changes: 1 addition & 1 deletion types/x-element.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions x-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ export default class XElement extends HTMLElement {
: host.setAttribute(property.attribute, serialization);
hostInfo.reflecting = false;
};
} else {
delete property.reflect;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We explicitly delete now in the false case so that we can depend on this being either undefined or a Function in later code.

}
}

Expand Down