Link to the code that reproduces this issue
https://github.com/Dev-Asfix/nextjs-404-back-bug.git
To Reproduce
- Run
npm run dev to start the development server
- Navigate to
/debug - the counter works, buttons respond correctly
- Navigate to a non-existent route, e.g.,
/debug/ruta-falsa
- Observe the Next.js 404 page
- Press the browser's "back" button
- Return to
/debug - the counter NO LONGER works. Buttons don't respond. Only static HTML is visible without JavaScript functionality.
Note: This only happens in development mode (npm run dev). Running npm run build followed by npm start works perfectly in production.
Current vs. Expected behavior
Current behavior:
After navigating to a 404 page and pressing the browser's back button, the page loses all interactivity. React state no longer works, the counter doesn't increment, and buttons don't respond to clicks. The page only displays static HTML.
Expected behavior:
The counter should continue working normally after navigating back from a 404 page. React state should be preserved and interactions should work as they do before visiting the 404 page or after a manual refresh (F5).
Additional observations:
- Manual refresh (F5) restores all functionality
- The problem does NOT occur in production (
npm start after npm build)
- My Next.js 15 projects never had this issue
- This is a brand new project with minimal code to isolate the problem
Provide environment information
Dependencies:
"next": "16.2.4",
"react": "19.2.4",
"react-dom": "19.2.4"
Which area(s) are affected? (Select all that apply)
Not Found
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
This issue consistently reproduces in a brand new Next.js 16 project created from scratch. My previous projects using Next.js 15 never had this problem.
What I've already verified:
- The problem ONLY occurs in development mode (
npm run dev)
- Production (
npm run build + npm start) works perfectly
- Manual page refresh (F5) restores functionality
- No custom configuration (default Next.js setup)
- Tested on Chrome and Firefox (same behavior)
- No errors appear in browser console or terminal
Suspicion: This might be related to how Next.js 16 handles hydration or router cache when navigating back from error pages (404) in development mode. The 404 page seems to break React state hydration on the previous page when using the back button.
Link to the code that reproduces this issue
https://github.com/Dev-Asfix/nextjs-404-back-bug.git
To Reproduce
npm run devto start the development server/debug- the counter works, buttons respond correctly/debug/ruta-falsa/debug- the counter NO LONGER works. Buttons don't respond. Only static HTML is visible without JavaScript functionality.Note: This only happens in development mode (
npm run dev). Runningnpm run buildfollowed bynpm startworks perfectly in production.Current vs. Expected behavior
Current behavior:
After navigating to a 404 page and pressing the browser's back button, the page loses all interactivity. React state no longer works, the counter doesn't increment, and buttons don't respond to clicks. The page only displays static HTML.
Expected behavior:
The counter should continue working normally after navigating back from a 404 page. React state should be preserved and interactions should work as they do before visiting the 404 page or after a manual refresh (F5).
Additional observations:
npm startafternpm build)Provide environment information
Dependencies: "next": "16.2.4", "react": "19.2.4", "react-dom": "19.2.4"Which area(s) are affected? (Select all that apply)
Not Found
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
This issue consistently reproduces in a brand new Next.js 16 project created from scratch. My previous projects using Next.js 15 never had this problem.
What I've already verified:
npm run dev)npm run build+npm start) works perfectlySuspicion: This might be related to how Next.js 16 handles hydration or router cache when navigating back from error pages (404) in development mode. The 404 page seems to break React state hydration on the previous page when using the back button.