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
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the
#ask-ai channel awaits if you're curious!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 🤦‍♂️
So doing db push fixed the issue for you?
Yep