Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/theme/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ const LEVEL_3_LINK_SELECTOR =
".theme-doc-sidebar-item-link-level-3 > .menu__link"
const LEVEL_3_PADDING_CLASS = "menu__link--level-3"
const SIDEBAR_MENU_SELECTOR = ".theme-doc-sidebar-menu"
const CRISP_WEBSITE_ID = "24b58135-86c7-4e4b-bf6e-cca862bc4b26"
const CRISP_SCRIPT_SRC = "https://client.crisp.chat/l.js"

declare global {
interface Window {
$crisp?: unknown[]
CRISP_WEBSITE_ID?: string
}
}

function applyLevel3PaddingClass() {
if (typeof document === "undefined") {
Expand All @@ -23,6 +32,24 @@ function applyLevel3PaddingClass() {
export default function Root({ children }: Props): ReactElement {
const location = useLocation()

useEffect(() => {
if (typeof document === "undefined") {
return
}

window.$crisp = window.$crisp ?? []
window.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID

if (document.querySelector(`script[src="${CRISP_SCRIPT_SRC}"]`)) {
return
}

const script = document.createElement("script")
script.src = CRISP_SCRIPT_SRC
script.async = true
document.head.appendChild(script)
}, [])

useEffect(() => {
if (typeof document === "undefined") {
return undefined
Expand Down
Loading