From 0b4a864002de90c5ba2521c4752d49265be99a9a Mon Sep 17 00:00:00 2001 From: David Hu Date: Tue, 16 Jul 2024 11:16:03 -0700 Subject: [PATCH 1/2] feat: new prop to toggle preconnect link tag --- README.md | 2 ++ src/components/LiveChatLoaderProvider.tsx | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6f644979..edb78809 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,7 @@ You can pass the following props to the `LiveChatLoaderProvider` provider: - `idlePeriod`: How long to wait in ms before loading the provider. Default is `2000`. Set to `0` to never load. This value is used in a `setTimeout` in browsers that don't support `requestIdleCallback`. +- `preconnect`: Determines whether a `link` tag with `rel=preconnect` is created. Default is `true`. - `beforeInit`: A function to be called after the script has loaded, but before the chat provider has been initialized (optional) - `onReady`: A function to be called once the script has been loaded, the chat provider has been initialized and is ready for use (optional) @@ -377,6 +378,7 @@ You can customise the Front placeholder icon by passing the following props to t - `containerClass`: Class to be added to the placeholder element, defaults to `live-chat-loader-placeholder` See the [official Front documentation](https://help.front.com/) for more details. +
diff --git a/src/components/LiveChatLoaderProvider.tsx b/src/components/LiveChatLoaderProvider.tsx index 03434dda..e8c27344 100644 --- a/src/components/LiveChatLoaderProvider.tsx +++ b/src/components/LiveChatLoaderProvider.tsx @@ -7,6 +7,12 @@ interface LiveChatLoaderProps { provider: Provider children: React.ReactNode idlePeriod?: number + /** + * determines whether to create a link tag that preconnect to the chat provider's domain + * + * @default true + */ + preconnect?: boolean providerKey: string appID?: string baseUrl?: string @@ -20,6 +26,7 @@ export const LiveChatLoaderProvider = ({ provider, children, idlePeriod = 5000, + preconnect = true, baseUrl, ...props }: LiveChatLoaderProps): JSX.Element | null => { @@ -45,11 +52,13 @@ export const LiveChatLoaderProvider = ({ return ( - + {preconnect && ( + + )} {children} ) From 085a6b9c366be5a0b5e6d8427024bceeb47bfa02 Mon Sep 17 00:00:00 2001 From: David Hu Date: Wed, 17 Jul 2024 10:19:22 -0700 Subject: [PATCH 2/2] feat: remove preconnect link tag since initialization is always deferred --- README.md | 1 - src/components/LiveChatLoaderProvider.tsx | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/README.md b/README.md index edb78809..0d0477ea 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,6 @@ You can pass the following props to the `LiveChatLoaderProvider` provider: - `idlePeriod`: How long to wait in ms before loading the provider. Default is `2000`. Set to `0` to never load. This value is used in a `setTimeout` in browsers that don't support `requestIdleCallback`. -- `preconnect`: Determines whether a `link` tag with `rel=preconnect` is created. Default is `true`. - `beforeInit`: A function to be called after the script has loaded, but before the chat provider has been initialized (optional) - `onReady`: A function to be called once the script has been loaded, the chat provider has been initialized and is ready for use (optional) diff --git a/src/components/LiveChatLoaderProvider.tsx b/src/components/LiveChatLoaderProvider.tsx index e8c27344..1840ee6e 100644 --- a/src/components/LiveChatLoaderProvider.tsx +++ b/src/components/LiveChatLoaderProvider.tsx @@ -7,12 +7,6 @@ interface LiveChatLoaderProps { provider: Provider children: React.ReactNode idlePeriod?: number - /** - * determines whether to create a link tag that preconnect to the chat provider's domain - * - * @default true - */ - preconnect?: boolean providerKey: string appID?: string baseUrl?: string @@ -26,7 +20,6 @@ export const LiveChatLoaderProvider = ({ provider, children, idlePeriod = 5000, - preconnect = true, baseUrl, ...props }: LiveChatLoaderProps): JSX.Element | null => { @@ -52,13 +45,6 @@ export const LiveChatLoaderProvider = ({ return ( - {preconnect && ( - - )} {children} )