diff --git a/web/src/elements/Base.ts b/web/src/elements/Base.ts index 243901e01..c50896957 100644 --- a/web/src/elements/Base.ts +++ b/web/src/elements/Base.ts @@ -13,12 +13,10 @@ import PFBase from "@patternfly/patternfly/patternfly-base.css"; import { Config, CurrentTenant, UiThemeEnum } from "@goauthentik/api"; -export function rootInterface(): T | undefined { - const el = Array.from(document.body.querySelectorAll("*")).filter( - (el) => el instanceof Interface, - ); - return el[0] as T; -} +type AkInterface = HTMLElement & { getTheme: () => Promise }; + +export const rootInterface = (): T | undefined => + document.body.querySelector('[data-ak-interface-root]') as T ?? undefined export function ensureCSSStyleSheet(css: CSSStyleSheet | CSSResult): CSSStyleSheet { if (css instanceof CSSResult) { @@ -171,7 +169,7 @@ export class AKElement extends LitElement { } } -export class Interface extends AKElement { +export class Interface extends AKElement implements AkInterface { @state() tenant?: CurrentTenant; @@ -186,6 +184,7 @@ export class Interface extends AKElement { document.adoptedStyleSheets = [...document.adoptedStyleSheets, ensureCSSStyleSheet(PFBase)]; tenant().then((tenant) => (this.tenant = tenant)); config().then((config) => (this.config = config)); + this.dataset.akInterfaceRoot = "true"; } _activateTheme(root: AdoptedStyleSheetsElement, theme: UiThemeEnum): void {