Skip to content

Commit 5e19f46

Browse files
MWPW-188304 Brand Concierge - Fix bootstrap api race condition (#5448)
1 parent fbdd057 commit 5e19f46

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

libs/blocks/brand-concierge/brand-concierge.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ export function getUpdatedChatUIConfig() {
4545
return chatUIConfig;
4646
}
4747

48+
function waitForCondition(checkFn, timeout = 5000, interval = 100) {
49+
return new Promise((resolve) => {
50+
const startTime = Date.now();
51+
const check = () => {
52+
if (checkFn()) {
53+
resolve(true);
54+
} else if (Date.now() - startTime >= timeout) {
55+
resolve(false);
56+
} else {
57+
setTimeout(check, interval);
58+
}
59+
};
60+
check();
61+
});
62+
}
63+
4864
async function openChatModal(initialMessage, el) {
4965
const innerModal = new DocumentFragment();
5066
const title = createTag('h1', { class: 'bc-modal-title' }, chatLabelText);
@@ -84,11 +100,22 @@ async function openChatModal(initialMessage, el) {
84100
const base = env.name === 'prod' ? 'experience.adobe.net' : 'experience-stage.adobe.net';
85101
const src = `https://${base}/solutions/experience-platform-brand-concierge-web-agent/static-assets/main.js`;
86102
await loadScript(src);
87-
window.adobe.concierge.bootstrap({
88-
instanceName: 'alloy',
89-
stylingConfigurations: getUpdatedChatUIConfig(),
90-
selector: `#${mountId}`,
91-
});
103+
104+
const bootstrapAPIReady = await waitForCondition(
105+
() => !!window.adobe?.concierge?.bootstrap,
106+
5000, // 5 seconds max wait
107+
100, // Check every 100ms
108+
);
109+
110+
if (bootstrapAPIReady) {
111+
window.adobe.concierge.bootstrap({
112+
instanceName: 'alloy',
113+
stylingConfigurations: getUpdatedChatUIConfig(),
114+
selector: `#${mountId}`,
115+
});
116+
} else {
117+
window.lana?.log('Brand Concierge: bootstrap API not available', { tags: 'brand-concierge', severity: 'critical' });
118+
}
92119
} else {
93120
// Legacy method: Use _satellite.track
94121
// eslint-disable-next-line no-underscore-dangle

0 commit comments

Comments
 (0)