diff --git a/layouts/MainLayout/MainLayout.tsx b/layouts/MainLayout/MainLayout.tsx index a9a0ed8..b23a919 100644 --- a/layouts/MainLayout/MainLayout.tsx +++ b/layouts/MainLayout/MainLayout.tsx @@ -1,16 +1,23 @@ import { Flex } from '@chakra-ui/react' -import React, { PropsWithChildren, ReactElement, useEffect } from 'react' +import React, { + PropsWithChildren, + ReactElement, + useEffect, + useState, +} from 'react' import { Footer } from '../../components/Footer' import { MainNavigation } from '../../components/MainNavigation' import useAppContext from '../../contexts/AppContext' -let shouldRender = process.env.NODE_ENV !== 'production' const correct_pass = process.env.NEXT_PUBLIC_PROD_PASS export default function MainLayout({ children, }: PropsWithChildren): ReactElement { const { menuItems, logo, ...contactDetails } = useAppContext() + const [shouldRender, setShouldRender] = useState( + process.env.NODE_ENV !== 'production' + ) useEffect(() => { const checkPassword = () => { @@ -18,7 +25,7 @@ export default function MainLayout({ window.sessionStorage.getItem('pass') || window.prompt('Password') if (password === correct_pass) { window.sessionStorage.setItem('pass', correct_pass) - shouldRender = true + setShouldRender(true) } else { checkPassword() } diff --git a/layouts/MainLayout/index.tsx b/layouts/MainLayout/index.tsx index 0384454..ac00e5e 100644 --- a/layouts/MainLayout/index.tsx +++ b/layouts/MainLayout/index.tsx @@ -1 +1,5 @@ -export { default as MainLayout } from './MainLayout' +import dynamic from 'next/dynamic' + +export const MainLayout = dynamic(() => import('./MainLayout'), { + ssr: false, +}) diff --git a/pages/[category]/[id].tsx b/pages/[category]/[id].tsx index c51c9af..21a9570 100644 --- a/pages/[category]/[id].tsx +++ b/pages/[category]/[id].tsx @@ -31,7 +31,6 @@ export default function Obituary({ obituary }: Props): ReactElement { type, } = obituary const fullname = [firstname, surname, name_misc].join(' ') - return (