fix: render GlobalAudioPlayer only on client side
This commit is contained in:
parent
6b4a81ce11
commit
5fcaef4da6
|
@ -1,3 +1,4 @@
|
||||||
|
import { GlobalAudioPlayer } from '@/components/GlobalAudioPlayer'
|
||||||
import { ProgressBar } from '@/components/ProgressBar/ProgressBar'
|
import { ProgressBar } from '@/components/ProgressBar/ProgressBar'
|
||||||
import { uiConfigs } from '@/configs/ui.configs'
|
import { uiConfigs } from '@/configs/ui.configs'
|
||||||
import { SearchBarProvider } from '@/context/searchbar.context'
|
import { SearchBarProvider } from '@/context/searchbar.context'
|
||||||
|
@ -8,7 +9,7 @@ import type { AppProps } from 'next/app'
|
||||||
import Head from 'next/head'
|
import Head from 'next/head'
|
||||||
import { ReactNode } from 'react'
|
import { ReactNode } from 'react'
|
||||||
import { LSDThemeProvider } from '../containers/LSDThemeProvider'
|
import { LSDThemeProvider } from '../containers/LSDThemeProvider'
|
||||||
import { GlobalAudioPlayer } from '@/components/GlobalAudioPlayer'
|
import { useHydrated } from '../utils/useHydrated.util'
|
||||||
|
|
||||||
type NextLayoutComponentType<P = {}> = NextComponentType<
|
type NextLayoutComponentType<P = {}> = NextComponentType<
|
||||||
NextPageContext,
|
NextPageContext,
|
||||||
|
@ -23,6 +24,8 @@ type AppLayoutProps<P = {}> = AppProps & {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function App({ Component, pageProps }: AppLayoutProps) {
|
export default function App({ Component, pageProps }: AppLayoutProps) {
|
||||||
|
const hydrated = useHydrated()
|
||||||
|
|
||||||
const getLayout =
|
const getLayout =
|
||||||
Component.getLayout ||
|
Component.getLayout ||
|
||||||
((page: ReactNode) => <DefaultLayout>{page}</DefaultLayout>)
|
((page: ReactNode) => <DefaultLayout>{page}</DefaultLayout>)
|
||||||
|
@ -95,7 +98,7 @@ export default function App({ Component, pageProps }: AppLayoutProps) {
|
||||||
<SearchBarProvider>
|
<SearchBarProvider>
|
||||||
{getLayout(<Component {...pageProps} />)}
|
{getLayout(<Component {...pageProps} />)}
|
||||||
</SearchBarProvider>
|
</SearchBarProvider>
|
||||||
<GlobalAudioPlayer />
|
{hydrated && <GlobalAudioPlayer />}
|
||||||
</LSDThemeProvider>
|
</LSDThemeProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
export const useHydrated = () => {
|
||||||
|
const [value, setValue] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setValue(true)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
Loading…
Reference in New Issue