OpenAIHonoFeb 19, 2026, 11:46 AM

v4.12.0

A condensed section focused on the key takeaways first.

Original Post

Quick Digest

Summary

A condensed section focused on the key takeaways first.

openaienmodel: gpt-5-mini-2025-08-07

Hono v4.12.0 — client helpers, middleware updates, and router performance

Key Points

  • client $path()
  • trie-router 1.5–2x faster
  • SSG redirect plugin

Summary

Hono v4.12.0 introduces client convenience methods and type helpers, middleware and adapter enhancements, and significant performance improvements in the router and response creation paths. This release focuses on practical ergonomics (client and SSG), better adapter metadata access, and measurable speedups for common routing and response patterns.

Key Points

  • Client: new $path() returns a plain path string (useful for routers and cache keys) while $url() still returns a full URL object.
  • Client types: ApplyGlobalResponse helper lets RPC clients include global error response shapes from onError or middleware.
  • SSG: redirectPlugin generates static HTML redirect pages (meta-refresh, canonical, robots noindex).
  • Middleware: basicAuth now supports an onAuthSuccess callback; trimTrailingSlash has alwaysRedirect to fix wildcard routes; language detector supports RFC4647 progressive truncation.
  • Adapters: getConnInfo() is available for AWS Lambda (API Gateway v1/v2, ALB), Cloudflare Pages, and Netlify to access client connection info.
  • Types: ExecutionContext includes an exports field for Cloudflare Workers (use module augmentation to add Wrangler types).
  • Performance: TrieRouter optimized (~1.5x–2.0x faster across nodes/runtimes). c.json() gained a fast path like c.text() with improved throughput and lower latency.

Action Items for Engineers

  • Prefer client.$path() when only the path string is needed; use $url() when a full URL object is required.
  • Add ApplyGlobalResponse to RPC client generics if you rely on global error shapes to get accurate response typings.
  • If targeting Cloudflare Workers, augment ExecutionContext to expose exports types from your toolchain (Wrangler).
  • Enable/verify trimTrailingSlash({ alwaysRedirect: true }) for apps using wildcard routes to ensure correct redirect behavior.
  • Run critical benchmarks after upgrading to validate performance gains in your environment.

Notable Changes

Performance improvements (trie-router and c.json()), SSG redirect support, more adapter getConnInfo() coverage, and new client/type ergonomics. See changelog for full PR list and contributors.

Full Translation

Translations

A translation section that keeps the flow of the original article.

openaijamodel: gpt-5-mini-2025-08-07

v4.12.0 リリースノート

Hono v4.12.0 — 2026-02-19

Hono v4.12.0 をリリースしました。このリリースでは、Hono クライアントの新機能、ミドルウェアの改善、アダプターの拡張、そしてルーターやコンテキスト周りの大幅なパフォーマンス改善が含まれます。

主な変更点

$path for Hono Client

Hono クライアントに $path() メソッドが追加され、フル URL ではなくパス文字列を返すようになりました。ルーティングやキャッシュキーなど、パス部分だけが必要な場合に便利です。

const client = hc < typeof app > ( 'http://localhost:8787' )
// Get the path string
const path = client . api . posts . $path ( )
// => '/api/posts'

// With path parameters
const postPath = client . api . posts [ ':id' ] . $path ( { param : { id : '123' } , } )
// => '/api/posts/123'

// With query parameters
const searchPath = client . api . posts . $path ( { query : { filter : 'test' } , } )
// => '/api/posts?filter=test'

$url() が URL オブジェクトを返すのに対し、$path() はプレーンなパス文字列を返すため、ルーターやキャッシュキーとして扱いやすくなります。Thanks @ShaMan123!

ApplyGlobalResponse 型ヘルパー (RPC Client)

新しい ApplyGlobalResponse 型ヘルパーにより、RPC クライアント内の全ルートに対してグローバルなエラー応答タイプを追加できます。app.onError() やグローバルミドルウェアの共通のエラー応答を型付けするのに有用です。

const app = new Hono ( )
  . get ( '/api/users' , ( c ) => c . json ( { users : [ 'alice' , 'bob' ] } , 200 ) )
  . onError ( ( err , c ) => c . json ( { error : err . message } , 500 ) )

type AppWithErrors = ApplyGlobalResponse < typeof app , {
  401 : { json : { error : string ; message : string } }
  500 : { json : { error : string ; message : string } }
} >

const client = hc < AppWithErrors > ( 'http://api.example.com' )
// Now client knows about both success and error responses
const res = await client . api . users . $get ( )
// InferResponseType includes { users: string[] } | { error: string; message: string }

Thanks @mohankumarelec!

SSG Redirect Plugin

SSG 用の redirectPlugin を追加しました。HTTP リダイレクト応答(301, 302, 303, 307, 308)に対して静的な HTML リダイレクトページを生成します。

import { toSSG } from 'hono/ssg'
import { defaultPlugin , redirectPlugin } from 'hono/ssg'

const app = new Hono ( )
app . get ( '/old' , ( c ) => c . redirect ( '/new' ) )
app . get ( '/new' , ( c ) => c . html ( 'New Page' ) )

// redirectPlugin must be placed before defaultPlugin
await toSSG ( app , fs , { plugins : [ redirectPlugin ( ) , defaultPlugin ( ) ] , } )

生成されるリダイレクトページには <meta http-equiv="refresh"> タグ、canonical リンク、robots の noindex メタタグが含まれます。Thanks @3w36zj6!

Basic Auth の onAuthSuccess コールバック

Basic Auth ミドルウェアに onAuthSuccess コールバックが追加されました。認証成功後に呼ばれ、Authorization ヘッダを再解析せずにコンテキスト変数の設定やログ出力ができます。非同期関数や verifyUser モードにも対応しています。

app . use ( '/auth/*' , basicAuth ( {
  username : 'hono' ,
  password : 'ahotproject' ,
  onAuthSuccess : ( c , username ) => {
    c . set ( 'user' , { name : username , role : 'admin' } )
    console . log ( `User ${ username } authenticated` )
  } ,
} ) )

Thanks @AprilNEA!

getConnInfo が AWS Lambda, Cloudflare Pages, Netlify に対応

getConnInfo() が以下のアダプターで利用可能になりました。

  • AWS Lambda (API Gateway v1/v2 と ALB をサポート)

    import { handle , getConnInfo } from 'hono/aws-lambda'

  • Cloudflare Pages

    import { handle , getConnInfo } from 'hono/cloudflare-pages'

  • Netlify

    import { handle , getConnInfo } from 'hono/netlify'

例:

app . get ( '/' , ( c ) => {
  const info = getConnInfo ( c )
  return c . text ( `Your IP: ${ info . remote . address } ` )
} )

Thanks @rokasta12!

Trailing Slash ミドルウェアの alwaysRedirect オプション

trailing slash ミドルウェアに alwaysRedirect オプションを追加しました。有効にすると、ハンドラー実行前にリダイレクトを行うため、ワイルドカードルートでの末尾スラッシュ処理が正しく動作します。

app . use ( trimTrailingSlash ( { alwaysRedirect : true } ) )
app . get ( '/my-path/*' , async ( c ) => { return c . text ( 'wildcard' ) } )

/my-path/something/ はワイルドカードハンドラーが実行される前に /my-path/something にリダイレクトされます。

プログレッシブなロケールコードの切り捨て

language ミドルウェア内の normalizeLanguage が RFC 4647 Lookup ベースのプログレッシブ切り捨てをサポートするようになりました。ja-JP のようなロケールは、supportedLanguages にベース言語 ja があれば ja にマッチします。

app . use ( '/*' , languageDetector ( {
  supportedLanguages : [ 'en' , 'ja' ] ,
  fallbackLanguage : 'en' ,
  order : [ 'cookie' , 'header' ] ,
} ) )

// Accept-Language: ja-JP → matches 'ja' // Accept-Language: ko-KR → falls back to 'en'

Thanks @sorafujitani!

ExecutionContext の exports フィールド

ExecutionContext 型に Cloudflare Workers 用の exports プロパティが追加されました。Wrangler が生成する型とモジュール拡張で型付けできます。

import 'hono'
declare module 'hono' {
  interface ExecutionContext {
    readonly exports : Cloudflare . Exports
  }
}

Thanks @toreis-up!

パフォーマンス改善

TrieRouter が 1.5x ~ 2.0x 高速化

TrieRouter を最適化し、spread 構文の削減、O(1) の hasChildren チェック、遅延正規表現生成、冗長処理の削除などを行いました。ベンチマーク結果(相対):

RouteNode.jsDenoBun
short static GET /user1.70x1.40x1.34x
dynamic GET /user/lookup/username/hey1.38x1.69x1.51x
wildcard GET /static/index.html1.51x1.72x1.43x
all together1.58x1.60x1.82x

Thanks @EdamAme-x!

c.json() の高速パス

c.json()c.text() と同様の高速パス最適化が追加されました。カスタムステータスやヘッダー、finalized 状態がない場合、Headers オブジェクトを割り当てずに直接 Response を生成します。一般的なパターンが高速化されます。

// This common pattern is now faster
return c . json ( { message : 'Hello' } )

ベンチマーク:

MetricBeforeAfterChange
Reqs/sec92,26895,244+3.2%
Latency5.42ms5.25ms-3.1%
Throughput17.24MB/s19.07MB/s+10.6%

Thanks @mgcrea!

変更履歴(抜粋)

  • feat(client): Add ApplyGlobalResponse type helper for RPC Client (#4556)
  • feat(ssg): add redirect plugin (#4599)
  • feat(client): $path (#4636)
  • feat(basic-auth): add context key and callback options (#4645)
  • feat(adapter): add getConnInfo for AWS Lambda, Cloudflare Pages, and Netlify (#4649)
  • feat(trailing-slash): add alwaysRedirect option to support wildcard routes (#4658)
  • feat(language): add progressive locale code truncation to normalizeLanguage (#4717)
  • feat(types): Add exports field to ExecutionContext (#4719)
  • perf(context): add fast path to c.json() matching c.text() optimization (#4707)
  • perf(trie-router): improve performance (1.5x ~ 2.0x) (#4724)
  • perf(context): use createResponseInstance for new Response (#4733)

他にもバグ修正や最適化、ドキュメント更新が含まれています。

新しいコントリビューター

  • @mixelburg (初めての貢献 #4729)
  • @aidenlx (初めての貢献 #4732)
  • @mohankumarelec (初めての貢献 #4556)
  • @ShaMan123 (初めての貢献 #4636)
  • @rokasta12 (初めての貢献 #4649)
  • @mgcrea (初めての貢献 #4707)

フルチェンジログ

v4.11.10...v4.12.0 を参照してください。


Contributors: yusukebe, usualoma, and 11 other contributors

Thanks to everyone who contributed and helped review this release!