Next.js Discord

Discord Forum

Deduping mutation requests

Unanswered
Polar bear posted this in #help-forum
Open in Discord
Polar bearOP
Hi all,

It is my understanding that when using the app directory, react will automatically dedupe requests that are made in a parent layout and its children however, I am not experiencing this.

In the /dashboard route of my app I have function called getUser() that is called in both the dashboard layout and the dashboard page being that both the layout and the page need the user data. If there is no user (the user has just signed up and it is their first time logging in) getUser will create the new user with the userId (received from Clerk which I am using as the authentication provider). However, being that the userId must be unique in the database (I am using Prisma to interface with PlanetScale MySQL) I am getting a unique error from the DB because the getUser function is being called both in the dashboard layout and page and it is attempting the create the user twice with the same userId.

Any idea why this request is not getting deduped here and what I can do to solve this issue?

3 Replies