News for hackers. Stuff that matters.
Re:You can make up HTML tags by dannye on Monday December 29, 2025 @03:30AM (#46418602)
this.querySelector will return nothing when you define this Web Component before (light)DOM is parsed, because the connectedCallback fires on the opening tag.

Above code will only work when the Web Component is defined after DOM has parsed; using "defer" or "import" makes your JS file execute after DOM is parsed, you "fixed" the problem without understanding what happened.

I blogged about this long time ago: https://dev.to/dannyengelman/web-component-developers-do-not...

Re:You can make up HTML tags by yawaramin on Monday December 29, 2025 @10:50AM (#46421839)
Well, that's why I include JS files at the bottom of my HTML body, to make sure to avoid exactly this problem: https://github.com/yawaramin/dream-html-ui/blob/92f2dfc51b75...
Re:You can make up HTML tags by dannye on Wednesday December 31, 2025 @04:02AM (#46442557)
One drawback.

► execute <script> at bottom of file

► execute <script defer>

Both do the same; they execute script after DOM was parsed. When your JS creates GUI you now have to battle FOUCs.

► "import" loads your script async

so it _could_ load before _all_ DOM has parsed... but 9999 out of 10000 scenarios it won't

Re:You can make up HTML tags by yawaramin on Thursday January 08, 2026 @09:25PM (#46549417)
That's why my JS doesn't create the GUI, it just attaches event handlers to the GUI rendered on the server. Check the link I posted above...