diff --git a/packages/twenty-front/src/modules/support/components/__stories__/SupportDropdown.stories.tsx b/packages/twenty-front/src/modules/support/components/__stories__/SupportDropdown.stories.tsx index c8f3d50e8..b1a06718d 100644 --- a/packages/twenty-front/src/modules/support/components/__stories__/SupportDropdown.stories.tsx +++ b/packages/twenty-front/src/modules/support/components/__stories__/SupportDropdown.stories.tsx @@ -53,6 +53,9 @@ export const Default: Story = { expect(await canvas.findByText('Support')).toBeInTheDocument(); await userEvent.click(canvas.getByText('Support')); + // Add delay to account for the timeout in useSupportChat + await new Promise((resolve) => setTimeout(resolve, 600)); + expect(await canvas.findByText('Documentation')).toBeInTheDocument(); expect(await canvas.findByText('Talk to us')).toBeInTheDocument(); }, diff --git a/packages/twenty-front/src/modules/support/hooks/useSupportChat.ts b/packages/twenty-front/src/modules/support/hooks/useSupportChat.ts index 6b2b76be7..ca8ea5193 100644 --- a/packages/twenty-front/src/modules/support/hooks/useSupportChat.ts +++ b/packages/twenty-front/src/modules/support/hooks/useSupportChat.ts @@ -12,15 +12,18 @@ const insertScript = ({ src, innerHTML, onLoad, + defer = false, }: { src?: string; innerHTML?: string; onLoad?: (...args: any[]) => void; + defer?: boolean; }) => { const script = document.createElement('script'); if (isNonEmptyString(src)) script.src = src; if (isNonEmptyString(innerHTML)) script.innerHTML = innerHTML; if (isDefined(onLoad)) script.onload = onLoad; + script.defer = defer; document.body.appendChild(script); }; @@ -50,6 +53,7 @@ export const useSupportChat = () => { insertScript({ src: url, + defer: true, onLoad: () => { window.FrontChat?.('init', { chatId, @@ -76,11 +80,13 @@ export const useSupportChat = () => { isDefined(currentWorkspaceMember) && !isFrontChatLoaded ) { - configureFront( - supportChat.supportFrontChatId, - currentUser, - currentWorkspaceMember, - ); + setTimeout(() => { + configureFront( + supportChat.supportFrontChatId as string, + currentUser, + currentWorkspaceMember, + ); + }, 500); } }, [ configureFront,