Skip to content

Commit

Permalink
in case of re-calling idos.init previous iframe is destroyed and new …
Browse files Browse the repository at this point in the history
…one is created properly
  • Loading branch information
Mohammed-Mamoun98 committed Dec 5, 2024
1 parent c6f6603 commit c845ba4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@ export class IframeEnclave implements EnclaveProvider {
}

async #loadEnclave() {
const hasIframe = document.getElementById(this.iframe.id);
if (hasIframe) {
const container = document.querySelector(this.container);
const iframeElem = document.getElementById(this.iframe.id);

if (iframeElem) {
console.warn("An Iframe already exists in the container");
return Promise.resolve();
container?.removeChild(iframeElem);
return new Promise((resolve) => this.#loadEnclave().then(resolve));
}

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy#directives
Expand Down Expand Up @@ -149,7 +152,6 @@ export class IframeEnclave implements EnclaveProvider {
this.iframe.style.setProperty(k, v);
}

const container = document.querySelector(this.container);
if (!container) throw new Error(`Can't find container with selector ${this.container}`);

container.appendChild(this.iframe);
Expand Down

0 comments on commit c845ba4

Please sign in to comment.