Custom server: app.render() not recognizing passed query params correctly #40936
Labels
area: Routing
Routing (next/router, next/navigation, next/link)
template: bug
A user has filled out the bug report template. Issue needs triaging
Verify 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:
Given
./pages/[id]exists, in 12.0.10, when visiting/page/123,ctx.router.query.idingetInitialPropsanduseRouter().query.idin components will return123.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.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
queryobject.After doing some digging, it seems like the
paramsreturned bydynamicRoute.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.idingetInitialPropsanduseRouter().query.idin components should return123.Link to reproduction
https://github.com/jackyef/next-1210-custom-server
To Reproduce
Clone the following repo.
next devand visit/123next devand visit/123router.query.idvalueThe text was updated successfully, but these errors were encountered: