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

TypeError: Cannot destructure property 'parallelRouterKey' of 'param' as it is null. #58485

Closed
1 task done
sebpalluel opened this issue Nov 15, 2023 · 4 comments · Fixed by #64271
Closed
1 task done
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@sebpalluel
Copy link

sebpalluel commented Nov 15, 2023

Link to the code that reproduces this issue

https://github.com/sebpalluel/parallel-router-key-destructure-property-error

To Reproduce

  1. Install the packages with pnpm i
  2. Start the application in development with pnpm run dev
  3. The main page at http://localhost:3000/ is working, displaying a layout with parallel routes displayed conditionally in desktop or mobile view size.
  4. Go to any non existing page like http://localhost:3000/dummy. It will display an error message coming from next/dist/client/components/layout-router.js"TypeError: Cannot destructure property 'parallelRouterKey' of 'param' as it is null."

Current vs. Expected behavior

It should display the placeholder not-found.txs

Verify canary release

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

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000
Binaries:
  Node: 20.1.0
  npm: 9.7.1
  Yarn: 1.22.19
  pnpm: 8.9.2
Relevant Packages:
  next: 14.0.3-canary.9
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

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

App Router

Additional context

When I comment out either AppNavLayoutDesktop or AppNavLayoutMobile in components/AppNavLayout.tsx, the error no longer occurs. Additionally, completely removing app/error.tsx also prevents the error, and instead, not-found.tsx is displayed as expected.

NEXT-2095

@sebpalluel sebpalluel added the bug Issue was opened via the bug report template. label Nov 15, 2023
@asplunds
Copy link

I discovered that this also happens when rendering a parallel route twice:

function Layout({ route }) {
   return <>
      {route}
      {route}
   </>
}

removing one of the instances makes the error go away but as soon as two or more are rendered it throws "TypeError: Cannot destructure property 'parallelRouterKey' of 'param' as it is null."

tested on Next.js 14.0.3

@ztanner ztanner added the linear: next Confirmed issue that is tracked by the Next.js team. label Jan 13, 2024
@sebpalluel
Copy link
Author

Issue is still happing with:


Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000
Binaries:
  Node: 20.1.0
  npm: 9.7.1
  Yarn: 1.22.19
  pnpm: 8.11.0
Relevant Packages:
  next: 14.1.1-canary.3 // Latest available version is detected (14.1.1-canary.3).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

@dorji-dev
Copy link

dorji-dev commented Apr 3, 2024

Facing same issue with next -> 14.1.4. I also had the same requirement as the OP where I needed to show a parallel route in different places based on whether it is mobile or desktop. Also would like to clarify that the error occurs only on initial navigations, if i refresh the same page, the error disappears and if i go back to another page and visit the same page again, it works.

Update: @sebpalluel I was able to solve the issue by wrapping the children slot i.e. the page.tsx file in a route group leaving the other parallel routes as it is. Don't know how it solved the issue but at least it is working for now. You can try it as well. Link here: https://github.com/dorji-dev/next_app/tree/main/src/app/features/(implementations)/intercepting-routes

ztanner added a commit that referenced this issue Apr 17, 2024
…64271)

### What
When rendering a parallel slot multiple times in a single layout, in
conjunction with using an error boundary, the following TypeError is
thrown:

> Cannot destructure property 'parallelRouterKey' of 'param' as it is
null

### Why
I'm not 100% sure of the reason, but I believe this is because of how
React attempts to dededupe (more specifically, "detriplficate") objects
that it sees getting passed across the RSC -> client component boundary
(and an error boundary is necessarily a client component). When React
sees the same object twice, it'll create a reference to that object and
then use that reference in future places where it sees the object. My
assumption is that there's a bug somewhere here, as the `LayoutRouter`
component for the subsequent duplicated parallel slots (after the first
one) have no props, hence the TypeError.

### How
Rather than passing the error component as a prop to `LayoutRouter`,
this puts it as part of the `CacheNodeSeedData` data structure. This is
more aligned with other properties anyway (such as `loading` and `rsc`
for each segment), and seems to work around this bug as the
`initialSeedData` prop is only passed from RSC->client once.

EDIT: Confirmed this is also fixed after syncing the latest React, due
to facebook/react#28669

Fixes #58485
Closes NEXT-2095
Copy link
Contributor

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

4 participants