Skip to content

Commit 0b4a864

Browse files
committed
feat: new prop to toggle preconnect link tag
1 parent 45c2482 commit 0b4a864

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ You can pass the following props to the `LiveChatLoaderProvider` provider:
127127
- `idlePeriod`: How long to wait in ms before loading the provider. Default is
128128
`2000`. Set to `0` to never load. This value is used in a `setTimeout` in
129129
browsers that don't support `requestIdleCallback`.
130+
- `preconnect`: Determines whether a `link` tag with `rel=preconnect` is created. Default is `true`.
130131
- `beforeInit`: A function to be called after the script has loaded, but before the chat provider has been initialized (optional)
131132
- `onReady`: A function to be called once the script has been loaded, the chat provider has been initialized and is ready for use (optional)
132133

@@ -377,6 +378,7 @@ You can customise the Front placeholder icon by passing the following props to t
377378
- `containerClass`: Class to be added to the placeholder element, defaults to `live-chat-loader-placeholder`
378379

379380
See the [official Front documentation](https://help.front.com/) for more details.
381+
380382
</details>
381383

382384
<details>

src/components/LiveChatLoaderProvider.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ interface LiveChatLoaderProps {
77
provider: Provider
88
children: React.ReactNode
99
idlePeriod?: number
10+
/**
11+
* determines whether to create a link tag that preconnect to the chat provider's domain
12+
*
13+
* @default true
14+
*/
15+
preconnect?: boolean
1016
providerKey: string
1117
appID?: string
1218
baseUrl?: string
@@ -20,6 +26,7 @@ export const LiveChatLoaderProvider = ({
2026
provider,
2127
children,
2228
idlePeriod = 5000,
29+
preconnect = true,
2330
baseUrl,
2431
...props
2532
}: LiveChatLoaderProps): JSX.Element | null => {
@@ -45,11 +52,13 @@ export const LiveChatLoaderProvider = ({
4552

4653
return (
4754
<LiveChatLoaderContext.Provider value={value}>
48-
<link
49-
href={baseUrl || chatProvider.domain}
50-
rel="preconnect"
51-
crossOrigin=""
52-
/>
55+
{preconnect && (
56+
<link
57+
href={baseUrl || chatProvider.domain}
58+
rel="preconnect"
59+
crossOrigin=""
60+
/>
61+
)}
5362
{children}
5463
</LiveChatLoaderContext.Provider>
5564
)

0 commit comments

Comments
 (0)