/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React from 'react'; import ReactDOM from 'react-dom/client'; import { BrowserRouter } from 'react-router-dom'; import { UserProvider } from './context/User'; import { StatusProvider } from './context/Status'; import { ThemeProvider } from './context/Theme'; import PageLayout from './components/layout/PageLayout'; import i18n, { loadLanguage } from './i18n/i18n'; import { bootstrapLanguage, createBrowserEnv } from './i18n/bootstrap'; import { API } from './helpers'; import './styles/tokens.css'; import './index.css'; import './styles/action-icons.css'; import './styles/org.css'; import './styles/prototype.css'; import './styles/user-center.css'; import './styles/org-page.css'; import './styles/center-layout.css'; import { applyThemeFromCache } from './helpers/theme'; import { installChunkReloadHandlers } from './helpers/chunkReload'; import ChunkErrorBoundary from './components/common/ChunkErrorBoundary'; // 在 React 渲染之前同步注入上次缓存的主题,避免首屏 FOUC applyThemeFromCache(); installChunkReloadHandlers(); import UiThemeProvider from './components/ui/UiThemeProvider'; // initialization console.log('[App] Initializing React application...'); const root = ReactDOM.createRoot(document.getElementById('root')); const renderApp = () => { console.log('[App] Rendering root component...'); root.render( , ); }; // 界面语言在渲染前判定:有本地缓存零等待,仅首访等待 /api/i18n/locale(超时回退), // 避免先渲染回退语言再闪切。判定异常也照常渲染。 // 用户选择与浏览器语言走请求头而非 query:gin 访问日志会把完整 query 连同客户端 IP 落盘, // 放在 URL 里等于每次首屏持久化一条"IP + 浏览器语言列表"指纹(R83 中-1) const fetchLocale = (params) => API.get('/api/i18n/locale', { headers: { 'X-UI-Language-Choice': params.user_lang || '', 'X-UI-Languages': params.browser || '', }, skipErrorHandler: true, disableDuplicate: true, }).then((res) => (res.data?.success ? res.data.data : null)); bootstrapLanguage(i18n, createBrowserEnv({ fetchLocale, loadLanguage })) .catch((error) => console.error('[App] Language bootstrap failed:', error)) .then(renderApp);