vercel / next.js

The React Framework
https://nextjs.org
MIT License
124.77k stars 26.63k forks source link

not-found loses context from layout on the re-occurring render #53147

Open ChiefORZ opened 1 year ago

ChiefORZ commented 1 year ago

Verify canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 21.6.0: Thu Jun  8 23:57:12 PDT 2023; root:xnu-8020.240.18.701.6~1/RELEASE_X86_64
Binaries:
  Node: 18.16.0
  npm: 9.5.1
  Yarn: 1.22.19
  pnpm: 8.6.10
Relevant Packages:
  next: 13.4.13-canary.0
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.6
Next.js Config:
  output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App Router

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

https://codesandbox.io/p/sandbox/elegant-joji-mxx7fn

To Reproduce

  1. Visit the CodeSandbox above
  2. Routing to /abc via a <Link /> - works
  3. Routing to /abc in the browser explodes 💥

Describe the Bug

To use next-intl you are supposed to use the <Link /> provided by next-intl/link. This needs a context provided by next-intl. This is done in the root layout.tsx (app/[locale]/layout.tsx). This worked fine with version 13.4.9

I tracked it down that the layout.tsx does not render on re-occurring renders - if you load the page and look at the console you can see:

[...not-found]/page.tsx
layout.tsx
not-found.tsx

[...not-found]/page.tsx
not-found.tsx
Error: No intl context found. Have you configured the provider?

On the first render the layout.tsx gets loaded perfects, on the second render the layout is skipped and therefore the context is not provided. It could be introduced by this PR https://github.com/vercel/next.js/pull/52589

Expected Behavior

The layout.tsx should be run on every render.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1471

amannn commented 1 year ago

Thank you for the great reproduction @ChiefORZ!

I've created an additional reproduction without next-intl, to make sure that it's not a library bug: CodeSandbox.

If you open https://sjdjxn-3000.csb.app/en/abc, you'll see false being rendered. This is a value from context that is configured in app/[locale]/layout.tsx. Navigating via Link works, as mentioned above.

dalechyn commented 1 year ago

+1, also can reproduce this

dalechyn commented 1 year ago

I can reproduce the same issue in a production build with other layouts, not just not found page.

hipdev commented 1 year ago

I'm having the same issue, a reload fixes it, but is very odd.

amannn commented 3 months ago

I've updated my CodeSandbox to use the latest stable version of Next.js (14.2.3 currently) and I think the bug has been resolved (new CodeSandbox).

murieldelvaux commented 1 month ago

I was able to render through the layout. In the project I'm working on, the architecture is features. Then: app > (features) > [...not-found] > page.tsx In my folder (features) I placed my layout file and it worked.