diff --git a/src/widget.ts b/src/widget.ts index c30c831..c483607 100644 --- a/src/widget.ts +++ b/src/widget.ts @@ -72,7 +72,7 @@ class ReactWidgetImpl< if (this.root === undefined || this.containerElement === undefined) { this.containerElement = document.createElement('div'); this.root = ReactDom.createRoot(this.containerElement); - this.connectionObserver.observe(this.parentDomNode); + this.connectionObserver?.observe?.(this.parentDomNode ?? this.containerElement); } this.domNodes.push(this.containerElement); nextSibling === null ? parent.append(this.containerElement) : nextSibling.before(this.containerElement);