Revalidate prisma query in `page.ts` RSC

I'm getting the same data every time I visit this route.
import { prisma } from "@acme/db";
import EditForm from "./edit-form";

export default async function Page({ params }: { params: { id: string } }) {
const account = await prisma.account.findUnique({
where: {
id: Number(params.id),
}
})

if (!account) return "Account doesn't exist";

return <EditForm account={account} />;
}
import { prisma } from "@acme/db";
import EditForm from "./edit-form";

export default async function Page({ params }: { params: { id: string } }) {
const account = await prisma.account.findUnique({
where: {
id: Number(params.id),
}
})

if (!account) return "Account doesn't exist";

return <EditForm account={account} />;
}
Is there a way to revalidate prisma queries in a RSC?
22 Replies
Neto
Neto2y ago
try add export const revalidate = 0; the explanation for it 0: Ensure a layout or page is always dynamically rendered even if no dynamic functions or dynamic data fetches are discovered. This option changes the default of fetch requests that do not set a cache option to 'no-store' but leaves fetch requests that opt into 'force-cache' or use a positive revalidate as is.
pedro77
pedro772y ago
The problem is revalidate and all the other functions like revalidatePath and revalidateTags all seem to work only for the fetch implementation next team made, not for prisma @nyx (Rustular DevRel) Tried it anyway, nothing changes The only way I don't get staled data is by doing full page reload which, I mean, it definitely sucks... the whole point of RSC is not to make a backend, isn't it? I feel like I need a backend right now
n1xx1
n1xx12y ago
does export const dynamic = "force-dynamic" help?
pedro77
pedro772y ago
No @n1xx1 So my question is: is it possible to revalidate anything other than fetch() functions? I asked in the Nextjs discord and nobody seems interested in answering that question
n1xx1
n1xx12y ago
I mean, it's supposed to work like you expect. I'm not sure what's going on
Neto
Neto2y ago
it should be able
pedro77
pedro772y ago
I'll work on a code sandbox
Neto
Neto2y ago
next dedupe fetch requests but i know that it will cache pages in general
n1xx1
n1xx12y ago
also it's a page with params, it's dynamic by default, it's not supposed to cache anything. try to reproduce in the codesandbox, maybe it's helpful! also make sure you're on next 13.4 I guess, I remember some issues with dev mode page caching
pedro77
pedro772y ago
I'm on it
pedro77
pedro772y ago
gifted-microservice-fphtss
CodeSandbox is an online editor tailored for web applications.
pedro77
pedro772y ago
Add and modify a post in that codesandbox please If you try to modify the second time, you'll get staled data
Neto
Neto2y ago
if i modify the code it creates a new sandbox for me
// page.tsx

import AddForm from "./add-form";

export const revalidate = 0;

export default function Page() {
return <AddForm />;
}
// page.tsx

import AddForm from "./add-form";

export const revalidate = 0;

export default function Page() {
return <AddForm />;
}
add this on page.tsx add that to the root page on /app/page.tsx
pedro77
pedro772y ago
I added that and doesn't help bro Bro, I feel like a beta tester, app router is stable, isn't it? How is this not working?
Neto
Neto2y ago
is not stable it never was
pedro77
pedro772y ago
The docs says is stable, they lie to us?
n1xx1
n1xx12y ago
ok I see what's going on, the data is changing but react-hook-form won't update your default variables
pedro77
pedro772y ago
Why not? it's unmounted everytime we use it react-hook-form can't persist data, as far as I can see
Neto
Neto2y ago
// add-form.tsx
router.refresh();
router.push("/");
// add-form.tsx
router.refresh();
router.push("/");
will purge the page and refresh accordingly
pedro77
pedro772y ago
Yeah, that might work (workaround), just I was expecting revalidatePath() to do what the name of the function suggests It's kinda disheartening to feel like nobody has thought of this simple issue, are these features getting adopted or is it just me? moment of sadness theoDisgusted
n1xx1
n1xx12y ago
I guess I never tried without doing a full refresh B)
pedro77
pedro772y ago
GitHub
Revalidate anything other than fetch() · Issue #49496 · vercel/ne...
Verify canary release I verified that the issue exists in the latest Next.js canary release Provide environment information Operating System: Platform: linux Arch: x64 Version: #22 SMP Tue Jan 10 1...
Want results from more Discord servers?
Add your server