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

Deep default.js is completely ignored #64708

Closed
2 of 4 tasks
aparx opened this issue Apr 18, 2024 · 6 comments · Fixed by #64748
Closed
2 of 4 tasks

Deep default.js is completely ignored #64708

aparx opened this issue Apr 18, 2024 · 6 comments · Fixed by #64748
Labels
bug Issue was opened via the bug report template. locked

Comments

@aparx
Copy link

aparx commented Apr 18, 2024

Link to the code that reproduces this issue

https://github.com/aparx/nextjs-deep-defaultjs-bug

To Reproduce

  1. Create a new Next application using the src folder and app router
  2. Create a parallel route, that contains a page and another subpage using a route parameter (e.g.: @test/[id]/page.js)
  3. Add a default to the subpage just created (e.g. @test/[id]/default.js)
  4. Create a route parameter at the root, add a page (e.g.: [id]/page.js) and add a subpage (e.g.: [id]/subpage/page.js)
  5. Start next and navigate to your just created subpage (e.g.: /someRandomId/subpage) - This should throw a 404

Current vs. Expected behavior

What is the issue?

The default.js examples suggest that it is possible to contain default.js files deeper than the parallel
route itself. Such that subfolders can contain a version of default Next displays when
a fallback is needed. This does not work as proposed in 14.2.0 & 14.2.2 when using a
route parameter.

Expected behaviour & issue

The route file-tree looks like this:

layout.tsx
- @team
-- [teamId]
    default.tsx
    page.tsx

- [teamId]
   page.tsx
-- settings
    page.tsx
   

Both are simultaneously rendered beneath each other in the root layout.tsx.

  1. We expect following when navigating to /testId/: (passed)

    1. the content of @team/[teamId]/page.tsx is rendered
    2. the content of [teamId]/page.tsx is rendered
  2. We expect following when navigating to /testId/settings: (failed)

    1. the content of @team/[teamId]/default.tsx is rendered (Unexpected)
    2. the content of [teamId]/settings/page.tsx is rendered (Only under a condition, see below)

By default, neither is rendered from point two, since a 404 is thrown. Only, when
adding a default.js at @team/ directly, [teamId]/settings/page.tsx is rendered. The more deeply
located default file is completely ignored.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 32638
  Available CPU cores: 16
Binaries:
  Node: 21.6.0
  npm: N/A
  Yarn: N/A
  pnpm: 8.2.0
Relevant Packages:
  next: 14.2.2 // Latest available version is detected (14.2.2).
  eslint-config-next: 14.2.2
  react: 18.0.0
  react-dom: 18.0.0
  typescript: 5.0.2
Next.js Config:
  output: N/A

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

Parallel & Intercepting Routes

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

next dev (local)

Additional context

I tested this reproduction with 14.0, 14.1 canary versions & the current latest 14.2.2

@aparx aparx added the bug Issue was opened via the bug report template. label Apr 18, 2024
@ztanner
Copy link
Member

ztanner commented Apr 18, 2024

Apologies for the confusion @aparx , the docs are outdated here and I'll work on a PR to fix them.

Parallel routes currently only support a single default for the slot, and that default should be defined at the root of the slot. The params it receives would be for the dynamic segments leading up to it.

ztanner added a commit that referenced this issue Apr 18, 2024
The `params` example in the docs for `default.js` have the slot/params
in the wrong order, giving the impression that you can deeply nest
`default` slots.

This clarifies that the params received by a slot are based on the
dynamic params leading up to the segment containing the slot.

Fixes #64708


Closes NEXT-3160
@aparx
Copy link
Author

aparx commented Apr 19, 2024

Hello, thanks for letting me know!

Are there plans on adding default.js the way they were described?

@ztanner
Copy link
Member

ztanner commented Apr 20, 2024

Hi @aparx -- there are not currently plans for this. Could you clarify a bit more what your desired behavior / use-case is? I could perhaps provide an alternate suggestion.

@aparx
Copy link
Author

aparx commented Apr 20, 2024

Hey Tanner,

I have a dashboard with three different parallel routes being displayed side by side. Some containing route params up to two directories deep. For some slots I need a default.js on different levels, to be able to use the supplied route parameters. I reckon I'm going to have to use normal pages, but the issue is they refetch on some soft navigation changes and also I'll kinda have to spam them in multiple places to get the desired behaviour, which is something I don't particularly want. I'm pretty certain I'll find a workaround that fits more with Next's design and concepts.

So thanks for helping and good luck down the road.

@frankievx
Copy link

Hey Tanner,

I have a dashboard with three different parallel routes being displayed side by side. Some containing route params up to two directories deep. For some slots I need a default.js on different levels, to be able to use the supplied route parameters. I reckon I'm going to have to use normal pages, but the issue is they refetch on some soft navigation changes and also I'll kinda have to spam them in multiple places to get the desired behaviour, which is something I don't particularly want. I'm pretty certain I'll find a workaround that fits more with Next's design and concepts.

So thanks for helping and good luck down the road.

I'm also interested in this functionality and the ability to have deeply nested slots that run code. My use case is essentially when I'm working on React Three Fiber projects I like to have the canvas and the webgl layer as a slot and then html on the main routes. This separation allows me to organize my react three fiber code effectively and in parallel with the html code.

Copy link
Contributor

github-actions bot commented May 7, 2024

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 May 7, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2024
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. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants