feat: i18n (i18next + react-i18next) zh/en + hydration fixes
- i18next + react-i18next: zh/en locales, language detection (localStorage > navigator > zh), settings language switcher - Components i18n'd: Navbar, Feed, NewPost, Modals, SettingsPage, SettingsProfile, AccountSecurity, RecoveryCodes - Fix hydration mismatch (spinner restart): forum name via cookie (Server Component reads cookie, SSR outputs name, no inline script DOM injection); remove createPortal in RecoveryCodes modal; i18n sync init (initImmediate) so SSR/CSR text matches - LoadingScreen: React-state name rendering (no script-injected nodes) - Fix double spinner in Feed; DM icon emoji → SVG in ConversationList # Conflicts: # components/AppProvider.js # components/NewPost.js
This commit is contained in:
1 parent
024b678ad3
commit
1934edebd5
20 files changed
+600
-169
No files matched your search
+13
-61
@@ -1,65 +1,17 @@
|
||||
'use client';
|
||||
// 主页:Server Component —— 从 cookie 读取缓存论坛名(SSR 首帧即输出),
|
||||
// 其余逻辑在客户端 HomeClient 中
|
||||
import { cookies } from 'next/headers';
|
||||
import HomeClient from './HomeClient';
|
||||
|
||||
// 主页:SPA 视图调度 (feed/post/new/admin/settings/messages)
|
||||
import { useState } from 'react';
|
||||
import AppProvider, { useApp } from '@/components/AppProvider';
|
||||
import Navbar from '@/components/Navbar';
|
||||
import Sidebar from '@/components/Sidebar';
|
||||
import Feed from '@/components/Feed';
|
||||
import PostDetail from '@/components/PostDetail';
|
||||
import NewPost from '@/components/NewPost';
|
||||
import AdminPage from '@/components/AdminPage';
|
||||
import SettingsPage from '@/components/SettingsPage';
|
||||
import UserProfile from '@/components/UserProfile';
|
||||
import CustomPage from '@/components/CustomPage';
|
||||
import MessagesPage from '@/components/MessagesPage';
|
||||
import ChatManager from '@/components/chat/ChatManager';
|
||||
import Modals from '@/components/Modals';
|
||||
import LoadingScreen from '@/components/LoadingScreen';
|
||||
|
||||
function HomeInner() {
|
||||
const { view, currentPostId, currentUsername, currentPageName, ready, forumName, forumNameLoaded } = useApp();
|
||||
const [modal, setModal] = useState(null); // null | login | register | report
|
||||
const [reportPostId, setReportPostId] = useState(null);
|
||||
|
||||
const openModal = (m) => setModal(m);
|
||||
const openReport = (postId) => { setReportPostId(postId); setModal('report'); };
|
||||
|
||||
// 初始化未完成:显示全屏加载页,避免未加载完的界面闪烁
|
||||
if (!ready) {
|
||||
return <LoadingScreen />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app-fade-in">
|
||||
<Navbar onOpenModal={openModal} />
|
||||
<ChatManager />
|
||||
|
||||
<div id="app" style={{ display: view === 'feed' ? 'flex' : 'none' }}>
|
||||
<Sidebar />
|
||||
<Feed onOpenModal={openModal} onReport={openReport} />
|
||||
</div>
|
||||
|
||||
{/* 独立页面 */}
|
||||
<div style={{ display: view !== 'feed' ? 'block' : 'none' }}>
|
||||
{view === 'post' && currentPostId && <PostDetail postId={currentPostId} />}
|
||||
{view === 'user' && currentUsername && <UserProfile username={currentUsername} />}
|
||||
{view === 'custom' && currentPageName && <CustomPage pageName={currentPageName} />}
|
||||
{view === 'new' && <NewPost />}
|
||||
{view === 'admin' && <AdminPage />}
|
||||
{view === 'settings' && <SettingsPage />}
|
||||
{view === 'messages' && <MessagesPage />}
|
||||
</div>
|
||||
|
||||
<Modals modal={modal} onClose={() => setModal(null)} reportPostId={reportPostId} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
// cookies() 是动态 API:禁止静态优化,每次请求 SSR
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<AppProvider>
|
||||
<HomeInner />
|
||||
</AppProvider>
|
||||
);
|
||||
let cachedName = '';
|
||||
try {
|
||||
cachedName = decodeURIComponent(cookies().get('forumlify-name')?.value || '');
|
||||
} catch (e) {
|
||||
cachedName = '';
|
||||
}
|
||||
return <HomeClient cachedName={cachedName} />;
|
||||
}
|
||||
Reference in new issue
Block a user