-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Description
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
Calling app.render(req, res, pathname, query) should not cause any issues.
Current Behavior
If app.render(req, res, pathname, query) is called and query is not an object, there will be a nasty error that will happen when calling Router.push (or any other router method that internally calls change).
Steps to Reproduce (for bugs)
- Set up a custom Next.js server
- Call
app.renderwhile passing an undefined value forquery. - Call
Router.pushwith the samepathnameand aquery.
Context
I was trying to move from a dynamic server to using static exports and had to deal with this bug for about two hours. I've gone deep into Next.js's source code so I can help pinpoint the exact path the bug follows. Basically, it's something like app.render -> renderToHTML -> doRender -> new Router.
To solve this issue it's as simple as modifying the shallow comparison function to be a bit more safe. It should check that both inputs are objects and if not return false. For now, I'm just doing the following:
server.get('*', (req, res, n) => {
const { pathname } = parse(req.url, true)
const route = routes[pathname]
if (route) return app.render(req, res, route.page, route.query || {})
n()
})This example in the wiki should be updated.
Your Environment
| Tech | Version |
|---|---|
| next | 3.2.2 |
| node | 8.4.0 |
| OS | macOS 10.12.6 |
| browser | Chrome 60.0.3112.113 |