Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not-found.tsx within the route segment does not catch notFound() #53344

Closed
1 task done
iDarkLightning opened this issue Jul 30, 2023 · 9 comments · Fixed by #53564
Closed
1 task done

not-found.tsx within the route segment does not catch notFound() #53344

iDarkLightning opened this issue Jul 30, 2023 · 9 comments · Fixed by #53564
Assignees
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@iDarkLightning
Copy link

iDarkLightning commented Jul 30, 2023

Verify canary release

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

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #22 SMP Tue Jan 10 18:39:00 UTC 2023
    Binaries:
      Node: 18.14.2
      npm: 9.5.0
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.4.13-canary.6
      eslint-config-next: 13.4.12
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.0.4
    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/kind-star-ztsjqt

To Reproduce

Create a not-found.tsx file inside a route segment. Call notFound() inside the corresponding page.tsx.

Describe the Bug

On versions greater than 13.4.9, a not-found.tsx does not catch the NEXT_NOT_FOUND error when thrown by the corresponding page.tsx and (most likely) pages further down the tree.

Expected Behavior

The expected behavior is that the closest not-found.tsx is rendered when NEXT_NOT_FOUND is thrown.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1490

@iDarkLightning iDarkLightning added the bug Issue was opened via the bug report template. label Jul 30, 2023
@darklight9811
Copy link

related #48763

@lucashfreitas
Copy link

experiencing the same problem after upgrading - had to downgrade it back to 13.4.9. Glad we had e2e tests to test 404 pages and it failed.

@balazsorban44
Copy link
Member

balazsorban44 commented Aug 2, 2023

See #48763 (comment)

More specifically

It's currently expected that /en/my-non-existent-page does not match/render app/[locale]/not-found.tsx.

So in your case, not-found.tsx needs to be higher up than the page you want to catch, ie. in this case at the root. Otherwise, the default 404 page will be rendered.

@darklight9811
Copy link

@balazsorban44 not any level of higher up, only root will catch it automatically.

@balazsorban44 balazsorban44 reopened this Aug 2, 2023
@balazsorban44
Copy link
Member

balazsorban44 commented Aug 2, 2023

Actually, on second look, it seems like a different issue, will track and investigate further!

@balazsorban44 balazsorban44 added the linear: next Confirmed issue that is tracked by the Next.js team. label Aug 2, 2023
@huozhi huozhi self-assigned this Aug 4, 2023
@kodiakhq kodiakhq bot closed this as completed in #53564 Aug 4, 2023
kodiakhq bot pushed a commit that referenced this issue Aug 4, 2023
### What & Why

The dynamic not-found boundary didn't work as expected as it was using the `pathname` to match how many levels of the segements should be matched. For dynamic routes this doesn't work, unlike normal page, the unmatched segment can also hit the not found boundary in the same level.

### How

Use `segment` of loader tree nodes to determine if not-found boundary searching is reached to the end instead of using `pathname`. 
> NOTE: For production `/_not-found` case since it's a valid page on production and still has the original tree, so we handle that as a special case to use the not found loader tree (with empty child routes) to render.

Fixes #53344
@MKraust
Copy link

MKraust commented Aug 17, 2023

As of 13.4.16 (same for 13.4.17) dynamic segment is catching it's NEXT_NOT_FOUND error, but shows pages/ 404 if no not-found.tsx is present in the dynamic segment.

Let's image this kind of app/ structure

app/
  not-found.tsx
  dynamic/
    layout.tsx
    [slug]/
      page.tsx

It seems like notFound() thrown inside app/dynamic/[slug]/page.tsx doesn't propagate to root app/not-found.tsx, instead it shows "pages" 404 with a app/dynamic/layout.tsx layout.
On the other hand, notFound() thrown inside non-existent segment, e.g. <host>/foo/bar, correctly shows a root app/not-found.tsx.

@huozhi
Copy link
Member

huozhi commented Aug 17, 2023

@MKraust mind creating a new issue with a reproduction for that? Thanks 🙏

@MKraust
Copy link

MKraust commented Aug 17, 2023

@MKraust mind creating a new issue with a reproduction for that? Thanks 🙏

Already created. Sorry, I forgot to reference this issue :(

#54174

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Sep 1, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants