Closed CaptainJKoB closed 3 years ago
If I understand correctly the output is correct, but the "dance" behind the heresy-ssr scene is not, right?
Yes, seems like it. Another thing i guess may be linked to this one is that if your render the elements in the example like this:
render(document.body, html`
<FirstElement props="${{ name: 'Gary' }}" />
<SecondElement props="${{ name: 'Gary' }}" />
`);
In oninit
of the component extending element
, the props
will return undefined
, in other cases it returns the set value.
OK, I've played around a bit with your example ... and here are my findings:
If you define a component that extends element it gets initialized multiple times.
That's not exactly correct. Try this instead:
const FirstElement = {
name: 'FirstElement',
extends: 'element',
oninit() {
this.firstElemInits = this.firstElemInits || 0;
console.log('FirstElement init:', ++this.firstElemInits);
},
render() {
this.html`FirstElement: ${ firstElemInits }`;
}
};
You will see the element is initialized once, and once only.
The final html output contains the last initialized component.
That is correct.
This behaviour is not present in heresy
That is because herey there uses native DOM behavior, SSR needs to work around the fact there is no DOM, so this might be a basicHTML bug instead, but I'm not 100% sure yet.
Works the same for ES6 class declaration.
Yeah, I think what happens is that there is some synchronous initialization and replacement in basicHTML that triggers oninit right away.
The good news is that the layout is the expected one, so the result doesn't break expectations (except for coupling init with non-component data).
The bad news is that this might take a while to be fixed properly, if I can fix it properly.
Meanwhile, I've realized Node 15 breaks completely ... which is a bigger bummer.
P.S. ok, the NodeJS 15 error is gone ... one thing per time ...
Interesting findings. Thank you for the insights.
The bad news is that this might take a while to be fixed properly, if I can fix it properly.
That's understandable. Opting towards built-in elements, anyways. I was just trying out different approaches.
Meanwhile, I've realized Node 15 breaks completely ... which is a bigger bummer.
Yeah, Node 15 is quite a bummer 😄
Fixed, it was a basicHTML bug indeed 👋
Hey 👋
Found some different behaviour between autonomous and built-in elements. If you define a component that extends
element
it gets initialized multiple times. The final html output contains the last initialized component. This behaviour is not present inheresy
(Codepen) Works the same for ES6 class declaration.Env: Node: 14.4.0
Reproduction sample:
Current console output:
Expected console output: