Next.js Discord

Discord Forum

Can't get client side routing to refetch server page data

Unanswered
Atlantic cod posted this in #help-forum
Open in Discord
Atlantic codOP
1. I would like to be able to refetch data in a server page when routing to it via Link or router.push().

2. Code
// src/app/admin/guests/[guestId]/page.tsx
import { PrismaClient } from '@prisma/client'
import EditGuestFormContainer from '~/components/NewGuestForm/EditGuestFormContainer'

const prisma = new PrismaClient()

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

  if (!guest) {
    return (
      <div>
    Not Found
      </div>
    )
  }

  return (
    <EditGuestFormContainer
      guest={{
    id: guest.id,
    firstName: guest.firstName,
    lastName: guest.lastName,
    allergies: [],
    foodChoice: guest.foodChoice,
    type: guest.type,
      }}
    />
  )
}

When I call a Server Action to mutate data and redirect back to the table list. Then click a Link to navigate back to the above page. It serves stale data in the form.

EditGuestFormContainer is a use client component

4. None of these work to solve my issue when added to the above page together or separate.
export const fetchCache = 'force-no-store'
export const revalidate = 0 // seconds
export const dynamic = 'force-dynamic'

3 Replies

Atlantic codOP
The server action is updating a record in the DB that's it.

Revalidate Path seems so far removed for this since the data I'm updating can potentially be displayed on numerous pages.

Are you saying I need to somehow dynamically track the pages the data will show up on and revalidate all of them when a record is updated?