I’m experiencing a strange bug in a Next.js 15 App Router application.
[Bug Description]
- On the page questions, the user edits some survey questions.
- Then, they navigate to the /info page using a top AppBar button (<Link href=... />).
- From the info page, they return to the questions page using useRouter().back().
- When they return, the previously edited questions appear to be not updated — the page shows the old question state instead.
[Additional Info]
- The /questions page is a Server Component (page.tsx) that fetches initial draft questions via getDraftQuestions(+id) which is DAL function and gets data using Prisma.
- These draft questions are passed as initialData into a Client Component (builder.tsx), which manages state with useState.
- From console logs, it looks like the server is not being called again, and the page shows stale data.
- Interestingly, this bug does not happen when the user simply navigates within the /questions page and calls useRouter().back() — the state remains correct in that case.
[Questions]
- What is the root cause of the stale data in this case?
- Is this caused by browser-level BFCache (Back-Forward Cache) behavior after navigation between pages?
- If so, what’s the recommended best practice in this kind of scenario to ensure the latest draft question data is shown?
- Should I force a router.refresh() on mount?
- Or is it better to move the draft question fetching entirely to the client side instead of relying on the Server Component?