🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
♻️ refactor(spa): use __DEV__ define instead of process.env.NODE_ENV (#14696)
Inneicd3716d5e729
diff --git a/src/components/BootErrorBoundary/index.tsx b/src/components/BootErrorBoundary/index.tsxindex 5cbd958ce36..b7293f2c355 100644--- a/src/components/BootErrorBoundary/index.tsx+++ b/src/components/BootErrorBoundary/index.tsx@@ -63,7 +63,7 @@ class BootErrorBoundary extends Component<BootErrorBoundaryProps, BootErrorBoundwindow.sessionStorage.removeItem(RELOAD_SESSION_KEY);} catch (error) {// Access to sessionStorage can fail in restricted environments; ignore.- if (process.env.NODE_ENV === 'development') {+ if (__DEV__) {console.warn('BootErrorBoundary failed to reset reload attempts', error);}}@@ -90,7 +90,7 @@ class BootErrorBoundary extends Component<BootErrorBoundaryProps, BootErrorBoundwindow.sessionStorage.setItem(RELOAD_SESSION_KEY, String(attempts + 1));} catch (error) {// If sessionStorage is unavailable, we still attempt a reload once.- if (process.env.NODE_ENV === 'development') {+ if (__DEV__) {console.warn('BootErrorBoundary failed to persist reload attempts', error);}}diff --git a/src/components/DebugNode.tsx b/src/components/DebugNode.tsxindex 3ec8274e5e9..d52568daa0b 100644--- a/src/components/DebugNode.tsx+++ b/src/components/DebugNode.tsx@@ -9,7 +9,7 @@ interface DebugNodeProps {}const DebugNode = ({ children, trace }: DebugNodeProps) => {- if (process.env.NODE_ENV !== 'development') return null;+ if (!__DEV__) return null;// eslint-disable-next-line react-hooks/rules-of-hooksuseEffect(() => {console.info(`[DebugNode] Suspense fallback active: ${trace}`);diff --git a/src/features/AgentMockDevtools/index.tsx b/src/features/AgentMockDevtools/index.tsxindex 6efca28ff6a..38e4f4dc3d9 100644--- a/src/features/AgentMockDevtools/index.tsx+++ b/src/features/AgentMockDevtools/index.tsx@@ -5,13 +5,12 @@ import { Fab } from './Fab';import { Modal } from './Modal';import { Popover } from './Popover';-const isDevEnv = process.env.NODE_ENV === 'development';const STORAGE_KEY = 'LOBE_AGENT_MOCK_ENABLED';const useDevtoolsEnabled = (): boolean => {const [enabled, setEnabled] = useState(false);useEffect(() => {- if (!isDevEnv) return;+ if (!__DEV__) return;setEnabled(localStorage.getItem(STORAGE_KEY) === '1');const onStorage = (e: StorageEvent) => {if (e.key === STORAGE_KEY) setEnabled(e.newValue === '1');@@ -37,7 +36,7 @@ const useIsAgentTopicRoute = (): boolean => {const AgentMockDevtools = memo(() => {const enabled = useDevtoolsEnabled();const isAgentTopicRoute = useIsAgentTopicRoute();- if (!isDevEnv || !enabled || !isAgentTopicRoute) return null;+ if (!__DEV__ || !enabled || !isAgentTopicRoute) return null;return (<><Fab />diff --git a/src/layout/GlobalProvider/FaviconProvider.tsx b/src/layout/GlobalProvider/FaviconProvider.tsxindex b75a645db2a..ca4ccec1688 100644--- a/src/layout/GlobalProvider/FaviconProvider.tsx+++ b/src/layout/GlobalProvider/FaviconProvider.tsx@@ -87,11 +87,9 @@ const updateFaviconDOM = (state: FaviconState, isDev: boolean) => {});};-const defaultIsDev = process.env.NODE_ENV === 'development';-export const FaviconProvider = memo<{ children: ReactNode }>(({ children }) => {const [currentState, setCurrentState] = useState<FaviconState>('default');- const [isDevMode, setIsDevModeState] = useState<boolean>(defaultIsDev);+ const [isDevMode, setIsDevModeState] = useState<boolean>(__DEV__);const setFavicon = useCallback((state: FaviconState) => {setCurrentState(state);diff --git a/src/layout/SPAGlobalProvider/index.tsx b/src/layout/SPAGlobalProvider/index.tsxindex 4f441d9a66b..93f1b50e996 100644--- a/src/layout/SPAGlobalProvider/index.tsx+++ b/src/layout/SPAGlobalProvider/index.tsx@@ -83,7 +83,7 @@ const SPAGlobalProvider = memo<PropsWithChildren>(({ children }) => {<Suspense><ImportSettings />{/* DevPanel disabled in SPA: depends on node:fs */}- {process.env.NODE_ENV === 'development' && <AgentMockDevtools />}+ {__DEV__ && <AgentMockDevtools />}</Suspense></ServerConfigStoreProvider></AppTheme>diff --git a/src/routes/(main)/agent/channel/detail/Body.tsx b/src/routes/(main)/agent/channel/detail/Body.tsxindex ac100a94e21..1ae0432a465 100644--- a/src/routes/(main)/agent/channel/detail/Body.tsx+++ b/src/routes/(main)/agent/channel/detail/Body.tsx@@ -319,12 +319,10 @@ function getFields(schema: FieldSchema[], sectionKey: string): FieldSchema[] {if (!section?.properties) return [];return section.properties- .filter((f) => !f.devOnly || process.env.NODE_ENV === 'development')+ .filter((f) => !f.devOnly || __DEV__).flatMap((f) => {if (f.type === 'object' && f.properties) {- return f.properties.filter(- (child) => !child.devOnly || process.env.NODE_ENV === 'development',- );+ return f.properties.filter((child) => !child.devOnly || __DEV__);}return f;});diff --git a/src/routes/(main)/agent/channel/platform/wechat/ConnectedInfo.tsx b/src/routes/(main)/agent/channel/platform/wechat/ConnectedInfo.tsxindex 313fbfabd25..ef3807d169e 100644--- a/src/routes/(main)/agent/channel/platform/wechat/ConnectedInfo.tsx+++ b/src/routes/(main)/agent/channel/platform/wechat/ConnectedInfo.tsx@@ -91,7 +91,7 @@ const WechatConnectedInfo = memo<WechatConnectedInfoProps>(value={currentConfig.applicationId}/>)}- {process.env.NODE_ENV === 'development' && (+ {__DEV__ && (<><ReadOnlyFielddescription={t('channel.wechatBotIdHint')}diff --git a/src/spa/router/desktopRouter.config.desktop.tsx b/src/spa/router/desktopRouter.config.desktop.tsxindex a338ba14346..44997e5ca2b 100644--- a/src/spa/router/desktopRouter.config.desktop.tsx+++ b/src/spa/router/desktopRouter.config.desktop.tsx@@ -82,8 +82,6 @@ import ShareTopicPage from '@/routes/share/t/[id]';import ShareTopicLayout from '@/routes/share/t/[id]/_layout';import { ErrorBoundary, redirectElement } from '@/utils/router';-const isDev = process.env.NODE_ENV === 'development';-// Desktop router configuration — all sync imports for Electron local buildexport const desktopRoutes: RouteObject[] = [{@@ -527,7 +525,7 @@ export const desktopRoutes: RouteObject[] = [},// Devtools route (outside main layout, dev-only)- ...(isDev+ ...(__DEV__? [{children: [diff --git a/src/spa/router/desktopRouter.config.tsx b/src/spa/router/desktopRouter.config.tsxindex aa06f19a8cb..23d1a686c68 100644--- a/src/spa/router/desktopRouter.config.tsx+++ b/src/spa/router/desktopRouter.config.tsx@@ -9,7 +9,7 @@ import {import { dynamicElement, dynamicLayout, ErrorBoundary, redirectElement } from '@/utils/router';const agentChatElement = dynamicElement(() => import('@/routes/(main)/agent'), 'Desktop > Chat');-const isDev = process.env.NODE_ENV === 'development';+// Desktop router configuration (declarative mode)export const desktopRoutes: RouteObject[] = [{@@ -651,7 +651,7 @@ export const desktopRoutes: RouteObject[] = [},// Devtools route (outside main layout, dev-only)- ...(isDev+ ...(__DEV__? [{children: [diff --git a/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts b/src/store/chat/slices/aiChat/actions/conversationLifecycle.tsindex 8f41c580e3c..632a4d306ab 100644--- a/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts+++ b/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts@@ -874,9 +874,7 @@ export class ConversationLifecycleActionImpl {// Dev-only fast path: fall back to slicing the first user message instead of calling// the LLM. Keeps chat logs uncluttered while still giving the topic a usable title.// Only honored in non-production builds so a misconfigured prod env can't disable it.- const shouldSliceTopicTitle =- process.env.NODE_ENV !== 'production' &&- process.env.NEXT_PUBLIC_DEV_DISABLE_AUTO_TOPIC === '1';+ const shouldSliceTopicTitle = __DEV__ && process.env.NEXT_PUBLIC_DEV_DISABLE_AUTO_TOPIC === '1';const applyTopicTitle = async (topicId: string, messages: UIChatMessage[]) => {if (!shouldSliceTopicTitle) {diff --git a/vitest.config.mts b/vitest.config.mtsindex 62e56d0ed96..cc3f584262a 100644--- a/vitest.config.mts+++ b/vitest.config.mts@@ -30,6 +30,12 @@ const alias = {};export default defineConfig({+ define: {+ '__CI__': process.env.CI === 'true' ? 'true' : 'false',+ '__DEV__': process.env.NODE_ENV !== 'production' ? 'true' : 'false',+ '__ELECTRON__': 'false',+ '__MOBILE__': 'false',+ },optimizeDeps: {exclude: ['crypto', 'util', 'tty'],include: ['@lobehub/tts'],