P
Prisma•3mo ago
äggelele

React strict mode MongoDB race condition

I'm using MongoDB Atlas through Prisma on my Express backend while my frontend uses React & Vite. When I do fetch requests in React they get sent twice because of strict mode. This causes a race condition that creates duplicate documents on creation even when using unique fields in a document. Any smart way to fix this? I know that I can just skip strict mode which decreases chances of simultaneous requests. But even without strict mode I don't like the possibility of an end user being able to create duplicates.
4 Replies
Prisma AI Help
Prisma AI Help•3mo ago
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the #ask-ai channel awaits if you're curious!
äggelele
äggeleleOP•3mo ago
Something I also thought of was throttling, but that still feels like I'm just "hoping" that the call is done. I had to do a db push 🤦‍♂️
Nurul
Nurul•3mo ago
So doing db push fixed the issue for you?
äggelele
äggeleleOP•3mo ago
Yep

Did you find this page helpful?