Skip to content
Discussion options

You must be logged in to vote

Yes, this is a common issue in Next.js development with Prisma.

The problem is not Server Actions themselves — it is that during development, Fast Refresh/hot reload can recreate modules multiple times, which creates multiple PrismaClient instances.

In production this usually does not happen because modules are initialized once.

The recommended approach is still to cache Prisma on globalThis.

Example:

import { PrismaClient } from '@prisma/client'

const globalForPrisma = globalThis as unknown as {
  prisma: PrismaClient | undefined
}

export const prisma =
  globalForPrisma.prisma ??
  new PrismaClient()

if (process.env.NODE_ENV !== 'production') {
  globalForPrisma.prisma = prisma
}

Why…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ddl360
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants