Skip to content

Commit

Permalink
fix: issue 4762 RELEASE (#322)
Browse files Browse the repository at this point in the history
## Related Issues

Related descope/etc#4762
  • Loading branch information
nirgur authored Nov 22, 2023
1 parent e8bb7ac commit 1dd6d1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
7 changes: 6 additions & 1 deletion packages/web-component/src/lib/descope-wc/BaseDescopeWc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@ class BaseDescopeWc extends HTMLElement {
}

async #loadDescopeUI() {
if (globalThis.DescopeUI) {
this.descopeUI = Promise.resolve(globalThis.DescopeUI);
return;
}

let version = (await this.#getConfig())?.projectConfig?.componentsVersion;

if (!version) {
Expand All @@ -478,7 +483,7 @@ class BaseDescopeWc extends HTMLElement {
`Make sure this URL is valid and return the correct script: "${scriptSrc}"`
);

res({} as DescopeUI);
res(undefined);
};

scriptEle.onload = () => {
Expand Down
15 changes: 5 additions & 10 deletions packages/web-component/src/lib/descope-wc/DescopeWc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
setPhoneAutoDetectDefaultCode,
} from '../helpers/templates';
import {
DescopeUI,
Direction,
FlowState,
NextFn,
Expand Down Expand Up @@ -651,7 +650,10 @@ class DescopeWc extends BaseDescopeWc {
}
}

async loadDescopeUiComponents(clone: any) {
async loadDescopeUiComponents(clone: DocumentFragment) {
const descopeUI = await this.descopeUI;
if (!descopeUI) return;

const descopeUiComponentsList = getDescopeUiComponentsList(clone);

await Promise.all(
Expand All @@ -660,13 +662,6 @@ class DescopeWc extends BaseDescopeWc {

if (isComponentAlreadyDefined) return undefined;

let descopeUI: DescopeUI;
try {
descopeUI = await this.descopeUI;
} catch (e) {
return undefined;
}

if (!descopeUI[tag]) {
this.loggerWrapper.error(
`Cannot load UI component "${tag}"`,
Expand All @@ -680,7 +675,7 @@ class DescopeWc extends BaseDescopeWc {
return await descopeUI[tag]();
} catch (e) {
// this error is thrown when trying to register a component which is already registered
// because the components are registered asynchronously, it might happen that the register fn is called twice
// when running 2 flows on the same page, it might happen that the register fn is called twice
// in case it happens, we are silently ignore the error
if (e.name === 'NotSupportedError') {
// eslint-disable-next-line no-console
Expand Down

0 comments on commit 1dd6d1d

Please sign in to comment.