Next.js Server Action 返回 undefined
Prisma @@map 是表名映射(模型 → 数据库表名),字段 @map 是列名映射。混淆会导致查询的表/列名不匹配。规则:模型 PascalCase + @@map('snake_case'),字段 camelCase(DB 用 snake_case 时加 @map)。 Zod 校验错误消息...
Prisma @@map 是表名映射(模型 → 数据库表名),字段 @map 是列名映射。混淆会导致查询的表/列名不匹配。规则:模型 PascalCase + @@map('snake_case'),字段 camelCase(DB 用 snake_case 时加 @map)。 Zod 校验错误消息...
Prisma $queryRaw 中 camelCase 列名必须加双引号:SELECT "newUserQuota" FROM users。不加双引号 PostgreSQL 会当作不区分大小写的标识符,找不到 camelCase 列。TS 类型声明也要与 SQL 别名一致。 Prisma 连接池...
Auth.js 5 signIn redirect:false 返回 { error, ok, status, url }。判断成功:!result.error && result.ok。注意 result.url 可能含 ?error= 参数,用 redirectTo 显式指定避免误判。 Nex...
Tailwind v4 升级后样式失效,大版本升级有 breaking changes。检查:① tailwind.config.ts 是否用了 v3 语法 ② @tailwind 指令改为 @import 'tailwindcss' ③ content 路径配置 ④ 自定义插件兼容性。建议看官方迁...
React Server Component 中使用 useState 报错,因为 Server Component 不能用 hooks。解决:① 把需要状态的组件拆成 Client Component(加 'use client') ② 父组件保持 Server Component 做数据获取,子...
Next.js 动态 import 水合报错,可能是动态组件的 SSR 输出与客户端不一致。加 ssr: false 避免服务端渲染,或确保组件在 SSR 和 CSR 中输出一致。 Prisma enum 在 TypeScript 中报错,确保:① 运行了 prisma generate ② im...
next-intl t() 模板字符串拼接报错,因为动态拼接翻译键不被支持。用显式 Record 映射替代 t(`${type}Opt`),改为 const labels: Record<string, string> = { ... } 然后 labels[type]。 generateStat...
revalidateTag vs revalidatePath:revalidateTag 清除特定 tag 的缓存(fetch 时用 next.tags 标记),revalidatePath 清除特定路径的缓存。数据变更后 revalidatePath 更直接,精细控制用 revalidateTa...
next/image 图片模糊或变形,检查:① 是否设置了 width/height 或 fill ② fill 模式需要父容器 position: relative ③ priority 只给 LCP 图片 ④ sizes 属性帮助浏览器选择正确尺寸 ⑤ 避免在 Server Component...
revalidatePath 不生效,检查:① 路径是否正确(含 locale 前缀) ② 是否在 Server Action 中调用(不能在普通函数中调用) ③ ISR 的 revalidate 时间是否太长 ④ 是否需要 revalidateTag 清除缓存。 Next.js 动态 impor...
Prisma 事务中 create 返回的 id 在 commit 前可能不可用。如果需要用 id 生成 slug,可以在事务内先 create 再 update slug,或用 cuid() 手动生成 id。注意 Prisma @default(cuid()) 在 create 时生成。 gen...
Next.js 15 中 cookies().set() 后跟 redirect() 不兼容,因为 redirect() 抛出特殊错误终止请求,不会包含之前设置的 cookie。解决:用 Server Action(cookies().set 在 Action 中正常工作)或渲染客户端组件处理。...
next-intl 翻译键缺失不报错是默认行为。要启用严格模式:在 next-intl 配置中设置 onError 回调,或用 getTranslations 时检查返回值。开发环境建议开启严格模式及早发现缺失键。 next/font 加载失败,检查:① 字体文件路径是否正确 ② 是否在 root...
router.push 不更新 URL,Next.js 15 + next-intl 在 useSession 触发 re-render 时可能取消 router.push 的 startTransition。解决:用 window.location.href 硬导航(认证流程的例外允许裸路径)。...
middleware 重定向循环,一般是认证逻辑和业务重定向冲突。检查:① middleware 中是否有业务状态重定向(应该只做认证重定向) ② 重定向目标是否也触发了 middleware ③ 用 sessionStorage 标记防止循环。 Auth.js 5 signIn redirect...
Next.js middleware 中 pathname 精确匹配失效,因为 intl 中间件处理后 pathname 含 locale 前缀(如 /zh/dashboard)。用 pathname.includes() 或 getLocaleFromPathname() 而非 pathname...
Next.js Server Action 返回 undefined,可能是 Action 函数没有 return 值,或 return 的对象结构不对。Server Action 应该返回 { success: boolean, data?: T, error?: string } 格式。 Pr...
Server Action 提交后不跳转,可能是用了 router.push 而非 window.location.href。Next.js 15 + next-intl 的 router.push 在 startTransition 内会被 toast 的状态更新中断。解决:用 window.lo...
Next.js middleware 中 pathname 精确匹配失效,因为 intl 中间件处理后 pathname 含 locale 前缀(如 /zh/dashboard)。用 pathname.includes() 或 getLocaleFromPathname() 而非 pathname...
Zod refine 校验不触发,检查:① refine 是否在 schema 末尾 ② 是否用了 safeParse(parse 会抛错) ③ refine 的 path 是否正确指向字段 ④ 异步 refine 用 superRefine + async。 Tailwind v4 升级后样式失...