vercel / vercel/next.js

The behaviour of encoded special characters in path params is not consistent between page.tsx and route.ts

Open
#64,952 1 comment 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/naughty-sinoussi-2cz5ks

To Reproduce
  1. Create a dynamic page.tsx route using a path parameter like /[pathParam]/ and {params}: {params: { pathParam: string }}
  2. Create a dynamic route.ts route using the same path parameter like /[pathParam]/ and {params}: {params: { pathParam: string }}
  3. Visit the page.tsx based route with special characters in the URL
  4. Visit the route.ts based route with special characters in the URL
Current vs. Expected behavior

I would expect Next.js' params object to behave the same whether it's used from page.tsx, route.ts, or useParams().

Instead pathParam is undecoded when used from page.tsx and useParams() but is decoded when used from route.ts.

/dynamic-page/%3F%2C%3D%2C%2F%2C%26%2Cшеллы

{
  "params": {
    "pathParam": "%3F%2C%3D%2C%2F%2C%26%2C%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"
  }
}

/dynamic-route/%3F%2C%3D%2C%2F%2C%26%2C%D1%88%D0%B5%D0%BB%D0%BB%D1%8B?

{
  "method": "GET",
  "params": {
    "pathParam": "?,=,/,&,шеллы"
  }
}
Provide environment information
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 14.2.0-canary.11 // There is a newer canary version (14.3.0-canary.21) available, please upgrade! 
  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)

Not sure

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

next dev (local)

Additional context

No response

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 with the linked CodeSandbox and reproduce the encoded-character behavior across the dynamic page.tsx route, route.ts route, and useParams(). Trace how each entry point produces pathParam; done means the params object is consistent across all three cases, with regression coverage added for the reproduced URLs.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, react, typescript
Domain
backend-api-design, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.