Delay loading support chat (#10234)
There are a lot of requests being done in parallel when you load the page, and the support chat is responsible for some of them. I don't think it's critical to have it upon loading so delaying it by 2 seconds
This commit is contained in:
@ -53,6 +53,9 @@ export const Default: Story = {
|
|||||||
expect(await canvas.findByText('Support')).toBeInTheDocument();
|
expect(await canvas.findByText('Support')).toBeInTheDocument();
|
||||||
await userEvent.click(canvas.getByText('Support'));
|
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('Documentation')).toBeInTheDocument();
|
||||||
expect(await canvas.findByText('Talk to us')).toBeInTheDocument();
|
expect(await canvas.findByText('Talk to us')).toBeInTheDocument();
|
||||||
},
|
},
|
||||||
|
|||||||
@ -12,15 +12,18 @@ const insertScript = ({
|
|||||||
src,
|
src,
|
||||||
innerHTML,
|
innerHTML,
|
||||||
onLoad,
|
onLoad,
|
||||||
|
defer = false,
|
||||||
}: {
|
}: {
|
||||||
src?: string;
|
src?: string;
|
||||||
innerHTML?: string;
|
innerHTML?: string;
|
||||||
onLoad?: (...args: any[]) => void;
|
onLoad?: (...args: any[]) => void;
|
||||||
|
defer?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
if (isNonEmptyString(src)) script.src = src;
|
if (isNonEmptyString(src)) script.src = src;
|
||||||
if (isNonEmptyString(innerHTML)) script.innerHTML = innerHTML;
|
if (isNonEmptyString(innerHTML)) script.innerHTML = innerHTML;
|
||||||
if (isDefined(onLoad)) script.onload = onLoad;
|
if (isDefined(onLoad)) script.onload = onLoad;
|
||||||
|
script.defer = defer;
|
||||||
document.body.appendChild(script);
|
document.body.appendChild(script);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -50,6 +53,7 @@ export const useSupportChat = () => {
|
|||||||
|
|
||||||
insertScript({
|
insertScript({
|
||||||
src: url,
|
src: url,
|
||||||
|
defer: true,
|
||||||
onLoad: () => {
|
onLoad: () => {
|
||||||
window.FrontChat?.('init', {
|
window.FrontChat?.('init', {
|
||||||
chatId,
|
chatId,
|
||||||
@ -76,11 +80,13 @@ export const useSupportChat = () => {
|
|||||||
isDefined(currentWorkspaceMember) &&
|
isDefined(currentWorkspaceMember) &&
|
||||||
!isFrontChatLoaded
|
!isFrontChatLoaded
|
||||||
) {
|
) {
|
||||||
configureFront(
|
setTimeout(() => {
|
||||||
supportChat.supportFrontChatId,
|
configureFront(
|
||||||
currentUser,
|
supportChat.supportFrontChatId as string,
|
||||||
currentWorkspaceMember,
|
currentUser,
|
||||||
);
|
currentWorkspaceMember,
|
||||||
|
);
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
configureFront,
|
configureFront,
|
||||||
|
|||||||
Reference in New Issue
Block a user