vercel / vercel/next.js

`generateStaticParams` not Passing Parent Params to Child in Nested Dynamic Routes

Open
#53,717 11 comments 15 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug linear: next
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

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 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64
    Binaries:
      Node: 18.12.1
      npm: 9.7.1
      Yarn: 1.22.19
      pnpm: 8.6.6
    Relevant Packages:
      next: 13.4.14-canary.0
      eslint-config-next: 13.4.13
      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://github.com/nikolailehbrink/generateStaticParams-Bug

To Reproduce
  • Clone the GitHub repository that contains the bug.
  • Install the necessary dependencies.
  • Start the development server.
  • Navigate to a nested route such as http://localhost:3000/12314/iasd.
  • Observe that the child page is accessible and the slug parameter is not available in the child's generateStaticParams.
Describe the Bug

I encountered a bug when using the generateStaticParams function with nested dynamic routes in Next.js. The parent's parameters are not being passed to the child's generateStaticParams, causing unexpected behavior in the generated static pages. According to the documentation, the expected behavior is:

Generate the parent segments first and use the result to generate the child segments.

However, in the provided example, the behavior is not consistent with this documentation, and the slug parameter from the parent route does not get passed to the child.

Expected Behavior

Expected Behavior:
The slug parameter generated in the parent's generateStaticParams should be available in the child's generateStaticParams.

NEXT-1509

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked generateStaticParams-Bug reproduction and visit the nested route /12314/iasd. Compare the observed behavior with the generateStaticParams documentation for generating params from the top down. Done means the parent's slug is available in the child's generateStaticParams and nested static pages behave as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, react
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.