Skip to content

v2: Calling await next() in global middleware causes request handlers to be called twice #1172

@beeequeue

Description

@beeequeue

Environment

Node 24, H3 v2 beta

Reproduction

https://github.com/beeequeue/h3-next-repro

Describe the bug

Calling await next() in global middleware causes request handlers to be called twice, as in the repro:

let value = 0

const app = new H3()
  .use(async (event, next) => {
    const start = Date.now()
    console.log(event.url.pathname)

    await next()

    console.log(`took ${Date.now() - start}ms`)
  })
  .get("/test", async () => {
    value++

    return "Ok"
  })

After calling GET /test value will be 2 and not 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions