Skip to content

Commit 638bc45

Browse files
committed
Use onInitCompleted callback for loading
1 parent 0a67ea5 commit 638bc45

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

src/providers/front.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,26 @@ const load = ({
4747
beforeInit()
4848

4949
window.FrontChat('init', {
50-
chatId: providerKey
50+
chatId: providerKey,
51+
onInitCompleted: () => {
52+
setState('complete')
53+
onReady()
54+
// 👇 Add state to Track when Front is fully initialized
55+
window.FrontChat.hasInitialized = true
56+
}
5157
//Read more: https://dev.frontapp.com/docs/chat-sdk-reference
5258
})
5359
})
54-
55-
// Continue as long as frontchat hasn’t already been initialised.
56-
if (loaded) {
57-
waitForLoad(
58-
() => window.FrontChat,
59-
// Allow frontchat to complete loading before removing fake widget
60-
() =>
61-
setTimeout(() => {
62-
setState('complete')
63-
onReady()
64-
}, 2000)
65-
)
66-
}
6760
return loaded
6861
}
69-
const open = () => window.FrontChat('show')
62+
63+
const open = (): void => {
64+
waitForLoad(
65+
() => window.FrontChat?.hasInitialized,
66+
() => window.FrontChat('show')
67+
)
68+
}
69+
7070
export default {
7171
domain,
7272
load,

0 commit comments

Comments
 (0)