Skip to content

Commit

Permalink
Fix ssr bug
Browse files Browse the repository at this point in the history
  • Loading branch information
the-kwisatz-haderach committed Nov 20, 2023
1 parent db4bca7 commit b4c7c4d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
13 changes: 10 additions & 3 deletions layouts/MainLayout/MainLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
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<any>): ReactElement {
const { menuItems, logo, ...contactDetails } = useAppContext()
const [shouldRender, setShouldRender] = useState(
process.env.NODE_ENV !== 'production'
)

useEffect(() => {
const checkPassword = () => {
const password =
window.sessionStorage.getItem('pass') || window.prompt('Password')
if (password === correct_pass) {
window.sessionStorage.setItem('pass', correct_pass)
shouldRender = true
setShouldRender(true)
} else {
checkPassword()
}
Expand Down
6 changes: 5 additions & 1 deletion layouts/MainLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default as MainLayout } from './MainLayout'
import dynamic from 'next/dynamic'

export const MainLayout = dynamic(() => import('./MainLayout'), {
ssr: false,
})
1 change: 0 additions & 1 deletion pages/[category]/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default function Obituary({ obituary }: Props): ReactElement {
type,
} = obituary
const fullname = [firstname, surname, name_misc].join(' ')

return (
<div>
<Head>
Expand Down

1 comment on commit b4c7c4d

@vercel
Copy link

@vercel vercel bot commented on b4c7c4d Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.