Skip to content

Conversation

@usualoma
Copy link
Member

Reference: #4196 (comment)

This is a bug that has existed since quite early on. After calling next(), param() and routePath() were not returning the correct values. I believe this needs to be fixed.

Although this usage pattern is not very common, since it involves a change to the core behavior, I think it would be appropriate to merge this change during the next major version update.

An app that can reproduce the bug

const app = new Hono()

app.use('/:all{.*}', async (c, next) => {
  console.log(routePath(c))
  await next()
  console.log(routePath(c)) // should be '/:all{.*}'
  console.log(c.req.param('all')) // should be the request path
})

app.get('/posts/:id', (c) => {
  return c.text(routePath(c))
})

export default app

Expected result

  • Outputs /:all{.*}, and the request path

Actual result

  • Outputs /posts/:id, and undefined

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code

@usualoma usualoma changed the title fix(compose): preserve c.req.routeIndex after next() fix(compose): preserve c.req.routeIndex across next() Sep 23, 2025
@codecov
Copy link

codecov bot commented Sep 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.26%. Comparing base (ba98aa2) to head (1b7414c).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4424   +/-   ##
=======================================
  Coverage   91.25%   91.26%           
=======================================
  Files         171      171           
  Lines       10913    10916    +3     
  Branches     3144     3147    +3     
=======================================
+ Hits         9959     9962    +3     
  Misses        953      953           
  Partials        1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@usualoma
Copy link
Member Author

Hi @yusukebe
Would you please review this?

Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Member

@usualoma

Thank you. Looks good to me!

Although this usage pattern is not very common, since it involves a change to the core behavior, I think it would be appropriate to merge this change during the next major version update.

It's hard to decide. I want to release this before the major version update, but we don't know if it will be soon or not. As you said, some users may be damaged. For now, keep it not merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants