You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:router.param() handlers are not called consistently, may be called multiples times, or not called at all, depending on the order they were created (and in particular, the order in relation to other verb handlers).
Actual behavior
When param() handlers are defined, whether they get called, how many times they get called, and in what order depends entirely on when the related verb was registered. This mostly happens when using multiple param() handlers for the same parameter. But there are also issues with just a single param() handler being called multiple times in some cases (see the last test in the example repo for a case of this happening).
All param() handlers should be called once, in order, for any verb that uses that parameter, regardless of what order they were registered in. Or
-- or --
The documentation should be updated to make it clear that only a single param() handler per param name is supported. But there is still a bug where a param() handler can get called more than once, like here:
router.use('/:id',(ctx,next)=>{console.log(use1');next();}).param('id',(id,ctx,next)=>{// This gets called twice for a `GET /:id` requestconsole.log('param1');next();}).get('/:id',(ctx)=>{console.log('get1');ctx.status=200;});
Describe the bug
Node.js version: 22.8.0
OS version:
Description:
router.param()
handlers are not called consistently, may be called multiples times, or not called at all, depending on the order they were created (and in particular, the order in relation to other verb handlers).Actual behavior
When
param()
handlers are defined, whether they get called, how many times they get called, and in what order depends entirely on when the related verb was registered. This mostly happens when using multipleparam()
handlers for the same parameter. But there are also issues with just a singleparam()
handler being called multiple times in some cases (see the last test in the example repo for a case of this happening).For example, given the following router:
a
GET /:id
request will ONLY call the last param handler. The first 2 handlers are ignored completely.Then there's this scenario where, if you have multiple matching verb handlers, some of the param handlers can get called multiple times:
In this case a
GET /:id
request will result in:so param handlers 2 and 3 get called twice.
Expected behavior
All
param()
handlers should be called once, in order, for any verb that uses that parameter, regardless of what order they were registered in. Or-- or --
The documentation should be updated to make it clear that only a single
param()
handler per param name is supported. But there is still a bug where aparam()
handler can get called more than once, like here:Code to reproduce
Tests added to this branch showing the bug:
https://github.com/joekrill/router/tree/params-bug
Checklist
The text was updated successfully, but these errors were encountered: