H3 · Migration

H30018Replace H3 v1 hooks that H3 v2 ignores

Flags onRequest and onBeforeResponse on handler objects, and onBeforeResponse and onAfterResponse in app options, which H3 v2 never calls.

Why it happens

H3 v2 replaced handler-object hooks with a middleware array and kept only onRequest, onResponse, and onError as app hooks. The old keys are copied onto the handler or config but never run, so authentication, logging, or header logic in them silently stops.

Fix

Move handler hooks into middleware, such as defineHandler({ middleware: [auth], handler }), and move onBeforeResponse or onAfterResponse app logic to onResponse.

Example

Move handler hooks into middleware

Before

export default defineHandler({
  onRequest: [auth],
  handler: () => "ok",
})

After

export default defineHandler({
  middleware: [auth],
  handler: () => "ok",
})

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --rules h3/migration/no-ignored-hooks
Copyright © 2026