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

Custom server: app.render() not recognizing passed query params correctly #40936

Open
1 task done
jackyef opened this issue Sep 27, 2022 · 2 comments
Open
1 task done
Labels
area: Routing Routing (next/router, next/navigation, next/link) template: bug A user has filled out the bug report template. Issue needs triaging

Comments

@jackyef
Copy link
Contributor

jackyef commented Sep 27, 2022

Verify canary release

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

Provide environment information

Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Fri Apr 2 22:23:49 UTC 2021
Binaries:
Node: 16.16.0
npm: 8.11.0
Yarn: 1.22.19
pnpm: 7.7.0
Relevant packages:
next: 12.3.2-canary.10
eslint-config-next: 12.3.0
react: 17.0.2
react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Since 12.1.0, passed query params to app.render() in a custom server implementation aren't getting recognized correctly.

Consider the following custom express server:

server.get('/:id', async (req, res) => {  
  return app.render(req, res, '/[id]', {id: req.params.id}, `/${req.params.id}`)
})

Given ./pages/[id] exists, in 12.0.10, when visiting /page/123, ctx.router.query.id in getInitialProps and useRouter().query.id in components will return 123.

image

This however is not the case since 12.1.0. The value would be the literal string "[id]" instead. This issue still happens in latest canary release.

image


FWIW, I can achieve the same thing in >= 12.1.0 by updating the line to the following. Though with that being said, I am not sure if the behavior change is expected, especially since app.render() does accept a query object.

server.get('/:id', async (req, res) => {  
  return app.render(req, res, `/${req.params.id}`)
})

After doing some digging, it seems like the params returned by dynamicRoute.match() is { '[id]': '[id]' } instead of { '[id]': '123' }, which could be the problem.

This commit (a1b8a96) seems to be the one that introduced the behavior difference.

Expected Behavior

The 12.0.10 behavior should persists.

When visiting /page/123, ctx.router.query.id in getInitialProps and useRouter().query.id in components should return 123.

Link to reproduction

https://github.com/jackyef/next-1210-custom-server

To Reproduce

Clone the following repo.

  1. Install next 12.0.10, run next dev and visit /123
  2. Install next 12.1.0, run next dev and visit /123
  3. See the difference of the router.query.id value
@jackyef jackyef added the template: bug A user has filled out the bug report template. Issue needs triaging label Sep 27, 2022
@balazsorban44 balazsorban44 added the area: Routing Routing (next/router, next/navigation, next/link) label Sep 27, 2022
@Enrique-Ambrocio
Copy link

Hi there! Is there any way I can help? I'm actually looking to contribute to my first open-source project.

@thiefjim
Copy link

same issue here #41383

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Routing Routing (next/router, next/navigation, next/link) template: bug A user has filled out the bug report template. Issue needs triaging
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants