diff --git a/src/components/table-of-contents.tsx b/src/components/table-of-contents.tsx index 797f904..cb5fe2a 100644 --- a/src/components/table-of-contents.tsx +++ b/src/components/table-of-contents.tsx @@ -285,10 +285,20 @@ export function TableOfContents({ showHeader = true }: TableOfContentsProps) { }, 2500) } - if (headings.length === 0) return null - + // 注意:这里不能 `return null`。 + // + // Astro 靠「渲染器探测」决定交给哪个框架渲染:@astrojs/react 的 check 会试渲染一次, + // 拿到 null 就认不出这是 React 组件;接着轮到 @astrojs/mdx 的 check,而它是把组件 + // 当普通函数**裸调**(不在 React 渲染树里),useState 找不到 dispatcher,于是每次 + // SSR 都往控制台打一条 "Invalid hook call"。页面本身没错,但那行日志很误导人。 + // + // 始终返回