Closed theengineear closed 3 years ago
@klebba — I'm having a hard time reproducing this issue in a test. Can you help be understand how this test isn't proving that x-element functions the way you want?
@theengineear Thanks for checking this out; seems I need to take another look!
Repro case:
<!doctype html>
<html>
<head>
<title>x-element initial</title>
<style>:root { color-scheme: dark }</style>
</head>
<body>
x-element issue <a href="https://github.com/Netflix/x-element/issues/89">#89</a>
<div>
<x-foo></x-foo>
<x-foo></x-foo>
</div>
<script type="module">
import XElement from 'https://cdn.jsdelivr.net/npm/@netflix/x-element@1.0.0-rc.43/x-element.js';
class Baz {
constructor() {
this.id = Math.floor(Math.random() * 100);
}
}
export default class XFooElement extends XElement {
static get properties() {
return {
bar: {
type: Baz,
internal: true,
initial: () => new Baz(),
},
};
}
static template(html) {
return ({ bar }) => html`
<div id="container">${ bar.id }</div>
`;
}
}
customElements.define('x-foo', XFooElement);
</script>
</body>
</html>
Ah... well, it would help if we released x-element
. This has been fixed, but we were sorta waiting for lit 2.0
to happen — it never did... I'll release today.
This explains why my test case (running against latest master
) didn't pick up this behavior but your example (running against the latest release) does!
I'll release today so you can pull in the newest behavior.
@klebba — Gonna merge this in since I think it's a good test case to have locked down.
When “initial” is provided with a non-literal (compound) value, the return value should never be shared across other instances of the element.
Closes #89