mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 12:37:20 +08:00
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:
parent
6ca44eea28
commit
69589807fd
@ -3,6 +3,7 @@ import type { Day } from '../types'
|
|||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import timezone from 'dayjs/plugin/timezone'
|
import timezone from 'dayjs/plugin/timezone'
|
||||||
import utc from 'dayjs/plugin/utc'
|
import utc from 'dayjs/plugin/utc'
|
||||||
|
import { IS_PROD } from '@/config'
|
||||||
import tz from '@/utils/timezone.json'
|
import tz from '@/utils/timezone.json'
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
@ -131,7 +132,7 @@ export type ToDayjsOptions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const warnParseFailure = (value: string) => {
|
const warnParseFailure = (value: string) => {
|
||||||
if (process.env.NODE_ENV !== 'production')
|
if (!IS_PROD)
|
||||||
console.warn('[TimePicker] Failed to parse time value', value)
|
console.warn('[TimePicker] Failed to parse time value', value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { RiAlertLine, RiBugLine } from '@remixicon/react'
|
|||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import Button from '@/app/components/base/button'
|
import Button from '@/app/components/base/button'
|
||||||
|
import { IS_DEV } from '@/config'
|
||||||
import { cn } from '@/utils/classnames'
|
import { cn } from '@/utils/classnames'
|
||||||
|
|
||||||
type ErrorBoundaryState = {
|
type ErrorBoundaryState = {
|
||||||
@ -54,7 +55,7 @@ class ErrorBoundaryInner extends React.Component<
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (IS_DEV) {
|
||||||
console.error('ErrorBoundary caught an error:', error)
|
console.error('ErrorBoundary caught an error:', error)
|
||||||
console.error('Error Info:', errorInfo)
|
console.error('Error Info:', errorInfo)
|
||||||
}
|
}
|
||||||
@ -262,13 +263,13 @@ export function withErrorBoundary<P extends object>(
|
|||||||
// Simple error fallback component
|
// Simple error fallback component
|
||||||
export const ErrorFallback: React.FC<{
|
export const ErrorFallback: React.FC<{
|
||||||
error: Error
|
error: Error
|
||||||
resetErrorBoundary: () => void
|
resetErrorBoundaryAction: () => void
|
||||||
}> = ({ error, resetErrorBoundary }) => {
|
}> = ({ error, resetErrorBoundaryAction }) => {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-[200px] flex-col items-center justify-center rounded-lg border border-red-200 bg-red-50 p-8">
|
<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>
|
<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>
|
<p className="mb-4 text-center text-red-600">{error.message}</p>
|
||||||
<Button onClick={resetErrorBoundary} size="small">
|
<Button onClick={resetErrorBoundaryAction} size="small">
|
||||||
Try again
|
Try again
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import type { FC } from 'react'
|
|||||||
import { headers } from 'next/headers'
|
import { headers } from 'next/headers'
|
||||||
import Script from 'next/script'
|
import Script from 'next/script'
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { IS_CE_EDITION } from '@/config'
|
import { IS_CE_EDITION, IS_PROD } from '@/config'
|
||||||
|
|
||||||
export enum GaType {
|
export enum GaType {
|
||||||
admin = 'admin',
|
admin = 'admin',
|
||||||
@ -32,7 +32,7 @@ const GA: FC<IGAProps> = ({
|
|||||||
if (IS_CE_EDITION)
|
if (IS_CE_EDITION)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
const cspHeader = process.env.NODE_ENV === 'production'
|
const cspHeader = IS_PROD
|
||||||
? (headers() as unknown as UnsafeUnwrappedHeaders).get('content-security-policy')
|
? (headers() as unknown as UnsafeUnwrappedHeaders).get('content-security-policy')
|
||||||
: null
|
: null
|
||||||
const nonce = extractNonceFromCSP(cspHeader)
|
const nonce = extractNonceFromCSP(cspHeader)
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import { headers } from 'next/headers'
|
import { headers } from 'next/headers'
|
||||||
import Script from 'next/script'
|
import Script from 'next/script'
|
||||||
import { memo } from 'react'
|
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 () => {
|
const Zendesk = async () => {
|
||||||
if (IS_CE_EDITION || !ZENDESK_WIDGET_KEY)
|
if (IS_CE_EDITION || !ZENDESK_WIDGET_KEY)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
const nonce = process.env.NODE_ENV === 'production' ? (await headers()).get('x-nonce') ?? '' : ''
|
const nonce = IS_PROD ? (await headers()).get('x-nonce') ?? '' : ''
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import type { FC } from 'react'
|
|||||||
import type { GithubRepo } from '@/models/common'
|
import type { GithubRepo } from '@/models/common'
|
||||||
import { RiLoader2Line } from '@remixicon/react'
|
import { RiLoader2Line } from '@remixicon/react'
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery } from '@tanstack/react-query'
|
||||||
|
import { IS_DEV } from '@/config'
|
||||||
|
|
||||||
const defaultData = {
|
const defaultData = {
|
||||||
stargazers_count: 110918,
|
stargazers_count: 110918,
|
||||||
@ -21,7 +22,7 @@ const GithubStar: FC<{ className: string }> = (props) => {
|
|||||||
const { isFetching, isError, data } = useQuery<GithubRepo>({
|
const { isFetching, isError, data } = useQuery<GithubRepo>({
|
||||||
queryKey: ['github-star'],
|
queryKey: ['github-star'],
|
||||||
queryFn: getStar,
|
queryFn: getStar,
|
||||||
enabled: process.env.NODE_ENV !== 'development',
|
enabled: !IS_DEV,
|
||||||
retry: false,
|
retry: false,
|
||||||
placeholderData: defaultData,
|
placeholderData: defaultData,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import type {
|
|||||||
} from '@/models/common'
|
} from '@/models/common'
|
||||||
import type { RETRIEVE_METHOD } from '@/types/app'
|
import type { RETRIEVE_METHOD } from '@/types/app'
|
||||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||||
|
import { IS_DEV } from '@/config'
|
||||||
import { get, post } from './base'
|
import { get, post } from './base'
|
||||||
import { useInvalid } from './use-base'
|
import { useInvalid } from './use-base'
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ export const useUserProfile = () => {
|
|||||||
profile,
|
profile,
|
||||||
meta: {
|
meta: {
|
||||||
currentVersion: response.headers.get('x-version'),
|
currentVersion: response.headers.get('x-version'),
|
||||||
currentEnv: process.env.NODE_ENV === 'development'
|
currentEnv: IS_DEV
|
||||||
? 'DEVELOPMENT'
|
? 'DEVELOPMENT'
|
||||||
: response.headers.get('x-env'),
|
: response.headers.get('x-env'),
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user