refactor: Replace direct `process.env.NODE_ENV` checks with `IS_PROD` and `IS_DEV` constants. (#30383)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
This commit is contained in:
yyh 2025-12-31 08:32:55 +08:00 committed by GitHub
parent 6ca44eea28
commit 69589807fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 11 deletions

View File

@ -3,6 +3,7 @@ import type { Day } from '../types'
import dayjs from 'dayjs'
import timezone from 'dayjs/plugin/timezone'
import utc from 'dayjs/plugin/utc'
import { IS_PROD } from '@/config'
import tz from '@/utils/timezone.json'
dayjs.extend(utc)
@ -131,7 +132,7 @@ export type ToDayjsOptions = {
}
const warnParseFailure = (value: string) => {
if (process.env.NODE_ENV !== 'production')
if (!IS_PROD)
console.warn('[TimePicker] Failed to parse time value', value)
}

View File

@ -4,6 +4,7 @@ import { RiAlertLine, RiBugLine } from '@remixicon/react'
import * as React from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import Button from '@/app/components/base/button'
import { IS_DEV } from '@/config'
import { cn } from '@/utils/classnames'
type ErrorBoundaryState = {
@ -54,7 +55,7 @@ class ErrorBoundaryInner extends React.Component<
}
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
if (process.env.NODE_ENV === 'development') {
if (IS_DEV) {
console.error('ErrorBoundary caught an error:', error)
console.error('Error Info:', errorInfo)
}
@ -262,13 +263,13 @@ export function withErrorBoundary<P extends object>(
// Simple error fallback component
export const ErrorFallback: React.FC<{
error: Error
resetErrorBoundary: () => void
}> = ({ error, resetErrorBoundary }) => {
resetErrorBoundaryAction: () => void
}> = ({ error, resetErrorBoundaryAction }) => {
return (
<div className="flex min-h-[200px] flex-col items-center justify-center rounded-lg border border-red-200 bg-red-50 p-8">
<h2 className="mb-2 text-lg font-semibold text-red-800">Oops! Something went wrong</h2>
<p className="mb-4 text-center text-red-600">{error.message}</p>
<Button onClick={resetErrorBoundary} size="small">
<Button onClick={resetErrorBoundaryAction} size="small">
Try again
</Button>
</div>

View File

@ -3,7 +3,7 @@ import type { FC } from 'react'
import { headers } from 'next/headers'
import Script from 'next/script'
import * as React from 'react'
import { IS_CE_EDITION } from '@/config'
import { IS_CE_EDITION, IS_PROD } from '@/config'
export enum GaType {
admin = 'admin',
@ -32,7 +32,7 @@ const GA: FC<IGAProps> = ({
if (IS_CE_EDITION)
return null
const cspHeader = process.env.NODE_ENV === 'production'
const cspHeader = IS_PROD
? (headers() as unknown as UnsafeUnwrappedHeaders).get('content-security-policy')
: null
const nonce = extractNonceFromCSP(cspHeader)

View File

@ -1,13 +1,13 @@
import { headers } from 'next/headers'
import Script from 'next/script'
import { memo } from 'react'
import { IS_CE_EDITION, ZENDESK_WIDGET_KEY } from '@/config'
import { IS_CE_EDITION, IS_PROD, ZENDESK_WIDGET_KEY } from '@/config'
const Zendesk = async () => {
if (IS_CE_EDITION || !ZENDESK_WIDGET_KEY)
return null
const nonce = process.env.NODE_ENV === 'production' ? (await headers()).get('x-nonce') ?? '' : ''
const nonce = IS_PROD ? (await headers()).get('x-nonce') ?? '' : ''
return (
<>

View File

@ -3,6 +3,7 @@ import type { FC } from 'react'
import type { GithubRepo } from '@/models/common'
import { RiLoader2Line } from '@remixicon/react'
import { useQuery } from '@tanstack/react-query'
import { IS_DEV } from '@/config'
const defaultData = {
stargazers_count: 110918,
@ -21,7 +22,7 @@ const GithubStar: FC<{ className: string }> = (props) => {
const { isFetching, isError, data } = useQuery<GithubRepo>({
queryKey: ['github-star'],
queryFn: getStar,
enabled: process.env.NODE_ENV !== 'development',
enabled: !IS_DEV,
retry: false,
placeholderData: defaultData,
})

View File

@ -23,6 +23,7 @@ import type {
} from '@/models/common'
import type { RETRIEVE_METHOD } from '@/types/app'
import { useMutation, useQuery } from '@tanstack/react-query'
import { IS_DEV } from '@/config'
import { get, post } from './base'
import { useInvalid } from './use-base'
@ -85,7 +86,7 @@ export const useUserProfile = () => {
profile,
meta: {
currentVersion: response.headers.get('x-version'),
currentEnv: process.env.NODE_ENV === 'development'
currentEnv: IS_DEV
? 'DEVELOPMENT'
: response.headers.get('x-env'),
},