From 48a71abb3d74cb5c043a5ebc79a59b5cbe3cefd4 Mon Sep 17 00:00:00 2001 From: DimaRGB Date: Thu, 14 Mar 2024 10:13:05 +0200 Subject: [PATCH] Allow to set domElement as ShadowRoot --- src/dom-element-getter-helpers.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dom-element-getter-helpers.ts b/src/dom-element-getter-helpers.ts index ffc72b3..612a731 100644 --- a/src/dom-element-getter-helpers.ts +++ b/src/dom-element-getter-helpers.ts @@ -2,20 +2,20 @@ import { AppProps } from "single-spa"; type AllProps = AppProps & ExtraProps & { - domElement?: HTMLElement; - domElementGetter?(): HTMLElement; + domElement?: HTMLElement | ShadowRoot; + domElementGetter?(): HTMLElement | ShadowRoot; // Old versions of single-spa had an appName prop appName?: string; }; interface HelperOpts { - domElementGetter?(): HTMLElement; + domElementGetter?(): HTMLElement | ShadowRoot; } export function chooseDomElementGetter( opts: HelperOpts, props: AllProps -): () => HTMLElement { +): () => HTMLElement | ShadowRoot { let domElementGetter; if (props.domElement) { @@ -39,11 +39,11 @@ export function chooseDomElementGetter( return () => { const domElement = domElementGetter(props); - if (!(domElement instanceof HTMLElement)) { + if (!(domElement instanceof HTMLElement || domElement instanceof ShadowRoot)) { throw Error( `single-spa's dom-element-getter-helpers: domElementGetter returned an invalid dom element for application or parcel '${ props.name - }'. Expected HTMLElement, received ${typeof domElement}` + }'. Expected HTMLElement or ShadowRoot, received ${typeof domElement}` ); } @@ -53,7 +53,7 @@ export function chooseDomElementGetter( function defaultDomElementGetter( props: AllProps -): () => HTMLElement { +): () => HTMLElement | ShadowRoot { const appName = props.appName || props.name; if (!appName) { throw Error(