This commit is contained in:
eric
2026-03-28 00:53:10 -05:00
parent b099437738
commit 2307411b37
4 changed files with 17 additions and 96 deletions

View File

@@ -1,7 +1,6 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { HomePageSkeleton } from "@/app/components/HomePageSkeleton";
import { triggerPay } from "@/app/lib/triggerPay";
import { getPayEnv, getDeviceFromEnv } from "@/app/lib/payEnv";
import { usePayStatusPoll } from "@/app/lib/usePayStatusPoll";
@@ -166,7 +165,10 @@ function readVipBootstrapState(): {
return { paidType: null, userName: null, userEmail: null };
}
/** 首页init 完成前若尚未从本地恢复 VIP不渲染落地页避免 H5 reload 后先闪未解锁) */
/**
* 首页:首帧以 localStorage 为准展示 VIP 控制台或访客落地页init 仅后台同步/校验,
* 仅在服务端明确「非 VIP」等异常时更新状态见 verifyInBackground / probe
*/
export default function HomeClient() {
const [paidType, setPaidType] = useState<string | null>(
() => readVipBootstrapState().paidType
@@ -178,7 +180,6 @@ export default function HomeClient() {
() => readVipBootstrapState().userEmail
);
const [payPendingOrderId, setPayPendingOrderId] = useState<string | null>(null);
const [initDone, setInitDone] = useState(false);
const savePaidType = useCallback((type: string | null) => {
if (type) setStorage("paidType", type);
@@ -526,7 +527,6 @@ export default function HomeClient() {
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get("type")?.trim() === "clean") {
clearAllStorage();
setInitDone(true);
return;
}
/* paid=1 来自 URL 时不再无条件设置,需通过 confirm 或 PB 校验 */
@@ -661,13 +661,7 @@ export default function HomeClient() {
}
};
void (async () => {
try {
await init();
} finally {
setInitDone(true);
}
})();
void init();
}, [
clearAllStorage,
getOrCreateUserId,
@@ -737,24 +731,19 @@ export default function HomeClient() {
}, [clearAllStorage]);
const isLoggedIn = paidType === "vip";
const showGuestLanding = initDone && !isLoggedIn;
return (
<>
<VipLayout isLoggedIn={isLoggedIn} userName={userName} userEmail={userEmail} onLogout={handleLogout}>
{isLoggedIn ? (
<DashboardPage userName={userName} userEmail={userEmail} />
) : showGuestLanding ? (
<>
<LandingPage
onJoin={handlePay}
onVerify={checkPaymentFromPB}
onVerifyByEmail={checkVerifyByEmail}
onVerifySuccess={handleVerifySuccess}
/>
</>
) : (
<HomePageSkeleton variant="main" />
<LandingPage
onJoin={handlePay}
onVerify={checkPaymentFromPB}
onVerifyByEmail={checkVerifyByEmail}
onVerifySuccess={handleVerifySuccess}
/>
)}
</VipLayout>
</>

View File

@@ -1,11 +1,13 @@
"use client";
import dynamic from "next/dynamic";
import { HomePageSkeleton } from "./components/HomePageSkeleton";
const HomeClient = dynamic(() => import("./HomeClient"), {
ssr: false,
loading: () => <HomePageSkeleton />,
/** 仅纯色底,避免分包加载前白屏;真正 VIP/非 VIP 界面由 HomeClient 首帧同步读 localStorage 渲染 */
loading: () => (
<div className="min-h-screen bg-[var(--background)]" aria-hidden />
),
});
export function HomeClientLoader() {

View File

@@ -1,63 +0,0 @@
function SkeletonBlocks() {
return (
<div className="space-y-6">
<div className="mx-auto h-9 max-w-lg rounded-lg bg-[var(--muted)] animate-pulse" />
<div className="mx-auto h-[min(40vh,280px)] w-full max-w-3xl rounded-2xl bg-[var(--muted)]/70 animate-pulse" />
<div className="flex flex-wrap justify-center gap-3">
<div className="h-12 w-40 rounded-xl bg-[var(--muted)] animate-pulse" />
<div className="h-12 w-40 rounded-xl bg-[var(--muted)] animate-pulse" />
</div>
<div className="mx-auto mt-8 max-w-2xl space-y-3">
<div className="h-4 w-full rounded bg-[var(--muted)] animate-pulse" />
<div className="h-4 w-[90%] rounded bg-[var(--muted)] animate-pulse" />
<div className="h-4 w-[75%] rounded bg-[var(--muted)] animate-pulse" />
</div>
</div>
);
}
type HomePageSkeletonProps = {
className?: string;
/** full整页含顶栏main仅主内容区已包在 VipLayout 内时用) */
variant?: "full" | "main";
};
/**
* 首页骨架Server/Client 均可引用),保证首屏 HTML 即有可见结构,避免白屏。
*/
export function HomePageSkeleton({
className = "",
variant = "full",
}: HomePageSkeletonProps) {
const main = (
<main className="mx-auto w-full max-w-[1200px] flex-1 px-4 py-8 sm:px-6">
<SkeletonBlocks />
</main>
);
if (variant === "main") {
return (
<div
className={`min-h-[50vh] bg-[var(--background)] text-[var(--foreground)] ${className}`}
aria-busy="true"
aria-label="页面加载中"
>
{main}
</div>
);
}
return (
<div
className={`flex min-h-screen flex-col bg-[var(--background)] text-[var(--foreground)] ${className}`}
aria-busy="true"
aria-label="页面加载中"
>
<header className="flex items-center justify-between border-b border-[var(--border)] px-4 py-3 sm:px-6">
<div className="h-7 w-28 rounded-md bg-[var(--muted)] animate-pulse" />
<div className="h-9 w-24 rounded-lg bg-[var(--muted)] animate-pulse" />
</header>
{main}
</div>
);
}

View File

@@ -1,16 +1,9 @@
import { HomePageSkeleton } from "./components/HomePageSkeleton";
import { HomeClientLoader } from "./HomeClientLoader";
export default function Page() {
return (
<div className="relative min-h-screen bg-[var(--background)]">
{/* SSR 即输出骨架JS 未执行前也不白屏 */}
<div className="pointer-events-none absolute inset-0 z-0 overflow-hidden">
<HomePageSkeleton />
</div>
<div className="relative z-[1] min-h-screen">
<HomeClientLoader />
</div>
<div className="min-h-screen bg-[var(--background)]">
<HomeClientLoader />
</div>
);
}