Skip to content

Navigation from not-found page to dynamically rendered page doesn't work #55141

@IrynaD25

Description

@IrynaD25

Link to the code that reproduces this issue or a replay of the bug

https://github.com/IrynaD25/my-app

To Reproduce

  1. npx create-next-app@latest
  2. use default settings
  3. create not-found.tsx with a link to the home page in the app folder:
import NextLink from 'next/link';

const NotFound = () => (
  <div>
    <h2>404 PAGE</h2>
    <NextLink href="/">
      GO HOME
    </NextLink>
  </div>
);

export default NotFound;
  1. call headers function in app/page.tsx in order to switch to dynamic rendering
import Image from 'next/image'
import { headers } from 'next/headers';
import styles from './page.module.css'

export default function Home() {
  const headersInstance = headers()

  return (
    <main className={styles.main}>
    // other code
    </main>
  )
}
  1. run next build
  2. run next start
  3. navigate to a page that does not exist (e.g. http://localhost:3000/fewfw)
  4. Click the 'GO HOME' link
  5. Observe that the url changes, but the UI stays the same

Current vs. Expected behavior

When navigating from not-found to the home page, the url correctly changes to the home page, but the UI remains unchanged.

  • This bug occurs when the home page is dynamically rendered
  • This bug occurs only after running next build and next start. There is no bug when running next dev.
  • When the prefetch prop on the NextLink component in the not found page is explicitly set to either true or false, the redirection to the home page works, as expected, and the home page is displayed upon clicking the link.

Current Behaviour

After clicking next/link on the not found page, the url changes, but the UI isn't changed (the not found page is still displayed instead of the home page)

Screen.Recording.2023-09-08.at.14.20.00.mov

Expected Behaviour

Clicking next/link on the not found page should redirect to the home page and display its content.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.6.0: Thu Mar  9 20:08:59 PST 2023; root:xnu-8020.240.18.700.8~1/RELEASE_X86_64
    Binaries:
      Node: 16.18.0
      npm: 8.19.2
      Yarn: 1.22.10
      pnpm: N/A
    Relevant Packages:
      next: 13.4.20-canary.21
      eslint-config-next: 13.4.19
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.2.2
    Next.js Config:
      output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Additional context

This bug occurs both locally and after deploying the app.
Locally, this bug occurs only after running next build and next start. There is no bug when running next dev.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.lockedstaleThe issue has not seen recent activity.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions