From 7b750eee4d84aac8130fd4a50de31ad30833ba36 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 3 Mar 2020 15:52:21 -0500 Subject: [PATCH] Add support for Preact X --- preact-shadow-root.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/preact-shadow-root.js b/preact-shadow-root.js index 8c00578..a7adb5a 100644 --- a/preact-shadow-root.js +++ b/preact-shadow-root.js @@ -17,7 +17,14 @@ export default class Shadow { this.update(this.props, true); } update(props, unrender) { - let root = render(unrender ? null : props.children[0], this.shadow, this.shadow.firstChild); + let child = props.children; + let replace; + // support Preact 8 and prior + if (child && child[0] && 'nodeName' in child[0]) { + child = child[0]; + replace = this.shadow.firstChild; + } + let root = render(unrender ? null : child, this.shadow, replace); if (unrender && root) root.remove(); } render() {}