fix(statuspill): wait for document.body before appending status pill when script loads before <body> is parsed; defer via DOMContentLoaded or requestAnimationFrame
This commit is contained in:
@@ -311,6 +311,15 @@ export class TypedserverStatusPill extends LitElement {
|
||||
*/
|
||||
public show(): void {
|
||||
if (!this.appended) {
|
||||
if (!document.body) {
|
||||
// Script loaded before <body> was parsed (async module) — wait for DOM
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', () => this.show(), { once: true });
|
||||
} else {
|
||||
requestAnimationFrame(() => this.show());
|
||||
}
|
||||
return;
|
||||
}
|
||||
document.body.appendChild(this);
|
||||
this.appended = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user