diff --git a/src/runtime/SrcDocIFrameController.ts b/src/runtime/SrcDocIFrameController.ts index b762527..b42dd7e 100644 --- a/src/runtime/SrcDocIFrameController.ts +++ b/src/runtime/SrcDocIFrameController.ts @@ -79,7 +79,9 @@ export class SrcDocIFrameController extends Disposable implements IEmbeddedConte this.addAnchorLinkHandlers(); this.handleHashChange(); - this.config.onload?.(this.host); + if (this.config.onload) { + this.dispose.add(() => this.config.onload?.(this.host)); + } } // finds all relative links (href^="#") and changes their click behavior diff --git a/src/types.ts b/src/types.ts index 120ea04..084afff 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,7 +9,7 @@ export interface EmbedsConfig { classNames?: string[]; styles?: Record; isolatedSandboxHostURIOverride?: string; - onload?: (host: HTMLIFrameElement) => void; + onload?: (host: HTMLIFrameElement) => (() => void) | void; } export type Unsubscribe = () => void;