Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set domElement as ShadowRoot #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/dom-element-getter-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { AppProps } from "single-spa";

type AllProps<ExtraProps = {}> = 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<ExtraProps = {}>(
opts: HelperOpts,
props: AllProps<ExtraProps>
): () => HTMLElement {
): () => HTMLElement | ShadowRoot {
let domElementGetter;

if (props.domElement) {
Expand All @@ -39,11 +39,11 @@ export function chooseDomElementGetter<ExtraProps = {}>(
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}`
);
}

Expand All @@ -53,7 +53,7 @@ export function chooseDomElementGetter<ExtraProps = {}>(

function defaultDomElementGetter<ExtraProps>(
props: AllProps<ExtraProps>
): () => HTMLElement {
): () => HTMLElement | ShadowRoot {
const appName = props.appName || props.name;
if (!appName) {
throw Error(
Expand Down