diff --git a/src/components/ui/portal/provider.tsx b/src/components/ui/portal/provider.tsx index 9ccfedca3e..484e0e6130 100644 --- a/src/components/ui/portal/provider.tsx +++ b/src/components/ui/portal/provider.tsx @@ -4,7 +4,7 @@ import { isClientSide } from '~/utils/env' export const useRootPortal = () => { const ctx = useContext(RootPortalContext) - if (!isClientSide()) { + if (!isClientSide) { return null } return ctx.to || document.body diff --git a/src/hooks/data/use-note.ts b/src/hooks/data/use-note.ts index 967a0ef25b..7300fb9e06 100644 --- a/src/hooks/data/use-note.ts +++ b/src/hooks/data/use-note.ts @@ -9,7 +9,7 @@ export const useNoteData = () => { const nid = useNoteNId() const searchParams = useMemo( - () => (isClientSide() ? new URLSearchParams(location.search) : null), + () => (isClientSide ? new URLSearchParams(location.search) : null), [nid], ) const password = searchParams?.get('password') @@ -31,7 +31,7 @@ export const useNoteNId = () => { export const useNoteByNidQuery = (nid: string) => { const searchParams = useMemo( - () => (isClientSide() ? new URLSearchParams(location.search) : null), + () => (isClientSide ? new URLSearchParams(location.search) : null), [nid], ) const password = searchParams?.get('password') diff --git a/src/utils/env.ts b/src/utils/env.ts index 28b3dd13ad..3854d22bc1 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -1,8 +1,4 @@ -export const isClientSide = () => { - return typeof window !== 'undefined' -} -export const isServerSide = () => { - return !isClientSide() -} +export const isClientSide = typeof window !== 'undefined' +export const isServerSide = !isClientSide export const isDev = process.env.NODE_ENV === 'development' diff --git a/src/utils/request.ts b/src/utils/request.ts index 3f118f3a4e..213df47b38 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -7,7 +7,7 @@ import { API_URL } from '~/constants/env' import PKG from '../../package.json' import { getToken } from './cookie' -import { isDev } from './env' +import { isDev, isServerSide } from './env' const genUUID = () => { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { @@ -40,7 +40,7 @@ $axios.interceptors.request.use((config) => { config.headers['x-uuid'] = uuid } - if (isDev) { + if (isDev && isServerSide) { console.log(`[Request]: ${config.url}`) }