This commit is contained in:
2026-04-14 12:38:51 +08:00
parent bb7e654589
commit 53a4174aa9
4 changed files with 35 additions and 22 deletions

17
src/pages/a/ClientApp.tsx Normal file
View File

@@ -0,0 +1,17 @@
'use client';
import List from './List.tsx';
// Client Component - 用于 hydration结构需要和 ServerApp 一致
declare global {
interface Window {
__SERVER_DATA__?: { version: string };
}
}
export default function ClientApp() {
const version = typeof window !== 'undefined' && window.__SERVER_DATA__?.version
? window.__SERVER_DATA__.version
: 'loading';
return <List version={version} />;
}

View File

@@ -1,18 +1,6 @@
import List from './List.tsx';
// 模拟异步获取数据
async function fetchData() {
await new Promise(resolve => setTimeout(resolve, 1000));
return { version: '2.0.0', timestamp: Date.now() };
}
// Server Component - 直接 await 获取数据
export default async function ServerApp() {
const data = await fetchData();
return (
<div>
<h2>Server Time: {new Date(data.timestamp).toLocaleTimeString()}</h2>
<List version={data.version} />
</div>
);
// Server Component - 通过 props 接收数据,不再自己 fetch
export default async function ServerApp({ version }: { version: string }) {
return <List version={version} />;
}