fix(SW-239): make contents in sidepeek component render serverside for seo

This commit is contained in:
Arvid Norlin
2024-08-09 15:28:22 +02:00
parent b9d63d9f01
commit 47c77b62d6
9 changed files with 908 additions and 910 deletions

View File

@@ -1,7 +1,13 @@
"use client"
import { useIsSSR } from "@react-aria/ssr"
import { Children, cloneElement, PropsWithChildren } from "react"
import { Dialog, DialogTrigger, Modal } from "react-aria-components"
import {
Dialog,
DialogTrigger,
Modal,
ModalOverlay,
} from "react-aria-components"
import { SidePeekProps } from "./types"
@@ -12,25 +18,31 @@ export default function SidePeek({
onClose,
activeContent,
}: PropsWithChildren<SidePeekProps>) {
return (
const isSSR = useIsSSR()
return isSSR ? (
<div>{children}</div>
) : (
<DialogTrigger>
<Modal
className={styles.sidePeek}
<ModalOverlay
className={styles.overlay}
isOpen={!!activeContent}
onOpenChange={onClose}
isDismissable
>
<Dialog className={styles.dialog}>
{({ close }) => (
<>
{Children.map(children, (child) => {
return cloneElement(child as React.ReactElement, {
onClose: close,
})
})}
</>
)}
</Dialog>
</Modal>
<Modal className={styles.sidePeek}>
<Dialog className={styles.dialog}>
{({ close }) => (
<>
{Children.map(children, (child) => {
return cloneElement(child as React.ReactElement, {
onClose: close,
})
})}
</>
)}
</Dialog>
</Modal>
</ModalOverlay>
</DialogTrigger>
)
}