Skip to content

Next.js 16.2.4 - Bug When Navigating Back from 404 in Development #93413

@Dev-Asfix

Description

@Dev-Asfix

Link to the code that reproduces this issue

https://github.com/Dev-Asfix/nextjs-404-back-bug.git

To Reproduce

  1. Run npm run dev to start the development server
  2. Navigate to /debug - the counter works, buttons respond correctly
  3. Navigate to a non-existent route, e.g., /debug/ruta-falsa
  4. Observe the Next.js 404 page
  5. Press the browser's "back" button
  6. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not FoundRelated to the not-found.tsx file or the notFound() function.

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions