差不
差不多楼主
Next.js 路由组 layout 中调用 auth() 报错,因为 layout 是所有子页面的公共外壳,async layout 会拖慢导航。解决:layout 保持同步,用客户端组件 + useSession() 读取 session 缓存。 Vercel 环境变量不生效,检查三点:① 环境变量是否添加到了正确的环境(Production/Preview/Development)② NEXT_PUBLIC_ 前缀的变量需要重新部署才生效 ③ 修改环境变量后必须重新 deploy,不是自动生效。 React Server Component 中使用 useState 报错,因为 Server Component 不能用 hooks。解决:① 把需要状态的组件拆成 Client Component(加 'use client') ② 父组件保持 Server Component 做数据获取,子组件 Client 做交互。