vercel / vercel/next.js

Special characters are not decoded in dynamic routes using app directory

Open
#48,058 1 comment 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64
    Binaries:
      Node: 16.19.0
      npm: 8.19.3
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.3.1-canary.0
      eslint-config-next: 13.3.0
      react: 18.2.0
      react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Metadata (metadata, generateMetadata, next/head, head.js), Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/jolly-dawn-irt1qj?file=%2FREADME.md

To Reproduce
  1. Create a new Next.js project and enable appDir under the experimental settings in next.config.js
  2. Create an app folder, as well as a dynamic route inside that folder by creating an [id] folder
  3. Log the params property from the page arguments to the console by using console.log(params)
  4. Start the development server using next dev
  5. Navigate to the dynamic route using characters that should be encoded (such as : and @)
  6. Observe how the values are not decoded before they are logged to the console
Describe the Bug

Special characters that are passed to dynamic routes (defined by using [id] notation in folders) are not decoded before they are passed to the page.js/layout.js/etc files in Next.js 13 with the app directory. An example being a route defined in my site as /status/[type]/[address], navigating to /status/java/play.hypixel.net:25565 will have the params.address value passed from the page being logged as play.hypixel.net%3A25565. These special characters are not being decoded using decodeURIComponent() before they are passed to the developer.

Expected Behavior

I would expect these special characters to be decoded before I receive them. I have to manually do address = decodeURIComponent(address) for the layout and page files of all dynamic routes.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

next start via my VPS

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 issue using an app-directory dynamic route such as /status/[type]/[address]. Trace how the encoded route parameter reaches page.js or layout.js, then verify that values such as play.hypixel.net%3A25565 are decoded before being exposed in params. The issue does not mention a repository file or test to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, react
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.