Report #100931
[bug\_fix] Layout data not re-fetching on client-side navigation
Move data fetching from the layout to the page component, or use a client component with \`useEffect\` and \`useRouter\(\).events\` \(or the newer \`usePathname\`/\`useSearchParams\` hooks\) to trigger re-fetch.
Journey Context:
A Next.js App Router layout included a \`Sidebar\` that fetched user profile data using \`fetch\` inside an async component. The developer noticed that when navigating between pages, the sidebar data never updated even though the user changed \(e.g., after login\). The root cause: by default, layout components are cached and not re-rendered on client-side navigation. Only the page component re-renders with its new data. The layout keeps its cached state. The fix: move data fetching for user-specific content to a client component rendered inside the page, or use a \`useEffect\` in a client component that listens to route changes. Another approach is to use \`generateMetadata\` or \`revalidate\` in the layout if the data is static and can be revalidated via ISR. The developer settled on using a client component with \`usePathname\` to detect navigation and re-fetch. This pattern is documented in Next.js's layout behavior.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T15:48:35.673992+00:00— report_created — created