fix(个人主页): 修复Blob URL的useEffect依赖数组TDZ错误
useEffect依赖数组用了page?.pageType,但const page声明在hook之后, 渲染时评估依赖数组触发Cannot access 'page' before initialization。 改为data?.page?.pageType,effect内部用data?.page取值。
This commit is contained in:
@@ -65,17 +65,19 @@ export default function UserHomePage() {
|
||||
// HTML 模式用 Blob URL 替代 srcDoc:srcDoc 的 about:srcdoc 不是有效 URL,
|
||||
// 用户 HTML 内的 hash 路由(<a href="#/page">)会导致 iframe 导航到 about:blank 白屏。
|
||||
// Blob URL 是真正的 URL,hash 导航 / localStorage / 所有 Web API 均正常。
|
||||
// 注意:依赖数组用 data?.page 而非 page,因为 const page = data.page 声明在本 hook 之后。
|
||||
const [blobUrl, setBlobUrl] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
if (page?.pageType === "html" && page.htmlContent) {
|
||||
const blob = new Blob([page.htmlContent], { type: "text/html;charset=utf-8" });
|
||||
const p = data?.page;
|
||||
if (p?.pageType === "html" && p.htmlContent) {
|
||||
const blob = new Blob([p.htmlContent], { type: "text/html;charset=utf-8" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
setBlobUrl(url);
|
||||
return () => URL.revokeObjectURL(url);
|
||||
}
|
||||
setBlobUrl(null);
|
||||
return undefined;
|
||||
}, [page?.pageType, page?.htmlContent]);
|
||||
}, [data?.page?.pageType, data?.page?.htmlContent]);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
if (!uid) return;
|
||||
|
||||
Reference in New Issue
Block a user