电子
电子古董楼主
next-intl 翻译键缺失不报错是默认行为。要启用严格模式:在 next-intl 配置中设置 onError 回调,或用 getTranslations 时检查返回值。开发环境建议开启严格模式及早发现缺失键。
React Server Component 中使用 useState 报错,因为 Server Component 不能用 hooks。解决:① 把需要状态的组件拆成 Client Component(加 'use client') ② 父组件保持 Server Component 做数据获取,子组件 Client 做交互。
Next.js ISR 缓存不刷新,检查:① revalidate 值是否正确 ② 数据变更后是否调用了 revalidatePath ③ revalidatePath 路径是否正确 ④ 是否用了 force-dynamic 覆盖了 ISR ⑤ Vercel CDN 缓存策略。
Next.js Server Action 返回 undefined,可能是 Action 函数没有 return 值,或 return 的对象结构不对。Server Action 应该返回 { success: boolean, data?: T, error?: string } 格式。