Skip to content

feat(mount): introduce Mount Middleware and deprecate app.mount - #5221

Merged
yusukebe merged 5 commits into
mainfrom
feat/mount-middleware
Oct 4, 2026
Merged

yusukebe merged 5 commits into
mainfrom
feat/mount-middleware

Conversation

@yusukebe

@yusukebe yusukebe commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

I realized that app.mount() doesn't need to be placed in hono-base.ts. The codebase of app.mount() is a little bit fat compared to other methods in hono-base.ts, though the lines are very few in the real world. Anyway, the unnecessary should be removed from hono-base.ts.

So, we can make it a middleware called Mount Middleware. The usage is below:

import { Router as IttyRouter } from 'itty-router'
import { Hono } from 'hono'
import { mount } from 'hono/mount'

const ittyRouter = IttyRouter()
ittyRouter.get('/hello', () => new Response('Hello from itty-router'))

const app = new Hono()
app.all('/itty-router/*', mount(ittyRouter.handle))

I think the API syntax is very Hono-like and love it.

As a result, the bundle size will be 501B smaller (vs current main):

CleanShot 2026-08-12 at 21 31 59@2x

This PR will obsolete app.mount() completely, so this is a breaking change. Should be introduced in the next major release v5.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

@yusukebe
yusukebe marked this pull request as draft August 12, 2026 12:27
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@codecov

codecov Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.30%. Comparing base (6abd35b) to head (23f2249).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5221      +/-   ##
==========================================
+ Coverage   80.24%   80.30%   +0.06%     
==========================================
  Files         148      149       +1     
  Lines       10472    10504      +32     
  Branches     2336     2347      +11     
==========================================
+ Hits         8403     8435      +32     
  Misses       2069     2069              

☔ View full report in Codecov by Harness.
📢 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.

@yusukebe yusukebe added the v5 label Aug 12, 2026
@yusukebe yusukebe mentioned this pull request Aug 12, 2026
19 of 23 tasks
@yusukebe

Copy link
Copy Markdown
Member Author

Hey @usualoma !

What do you think of moving the mount feature from hono-base.ts to middleware? I want your opinion on the direction only (no implementation yet)!

@usualoma

Copy link
Copy Markdown
Member

@yusukebe
That's a great change!

I think mount is a feature that symbolizes Hono, but I don't think it's a “characteristic of the Hono instance itself,” so I think it makes sense for it to be implemented as middleware (which will also make the Hono instance smaller).

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

Bundle size check

main (95eb860) #5221 (156878b) +/-
Bundle Size (B) 18,335B 18,335B 0B
Bundle Size (KB) 17.91K 17.91K 0K

Compiler Diagnostics (tsc)

main (95eb860) #5221 (156878b) +/-
Files 83 83 0
Lines 59,444 59,446 +2
Identifiers 60,624 60,625 +1
Symbols 106,532 106,532 0
Types 163,092 163,092 0
Instantiations 414,023 414,023 0
Memory used 205,718K 209,114K +3,396K
I/O read 0s 0.01s +0.01s
I/O write 0s 0s 0s
Parse time 0.19s 0.3s +0.11s
Bind time 0.07s 0.11s +0.04s
Check time 0.82s 1.26s +0.44s
Emit time 0s 0s 0s
Total time 1.08s 1.67s +0.59s

Compiler Diagnostics (typescript-go)

main (95eb860) #5221 (156878b) +/-
Files 215 215 0
Lines 121,006 121,008 +2
Identifiers 107,352 107,353 +1
Symbols 181,164 181,164 0
Types 262,348 262,348 0
Instantiations 621,588 621,588 0
Memory used 154,110K 154,076K -34K
Memory allocs 1,784,037 1,783,986 -51
Config time 0.001s 0.001s 0s
BuildInfo read time 0s 0s 0s
Parse time 0.053s 0.094s +0.041s
Bind time 0s 0s 0s
Check time 0.289s 0.459s +0.17s
Emit time 0.003s 0.004s +0.001s
Changes compute time 0.015s 0.036s +0.021s
Total time 0.382s 0.629s +0.247s

Reported by octocov

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

HTTP Performance Benchmark

Framework Runtime Average Ping Query Body
hono (origin/main) bun 35,410.78 48,934.60 31,954.58 25,343.16
hono (current) bun 35,642.95 49,025.56 31,965.47 25,937.82
Change +0.66% +0.19% +0.03% +2.35%

@yusukebe
yusukebe marked this pull request as ready for review October 1, 2026 12:09
@yusukebe yusukebe changed the title feat(mount)!: introduce Mount Middleware and obsolete app.mount feat(mount): introduce Mount Middleware and deprecate app.mount Oct 1, 2026
@yusukebe

yusukebe commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Hey @usualoma

I am planing introuce Mount Middleware and depracate app.mount now in v4 and, obsolute app.mount in v5.

I think it's okay to obsolete app.mount completely in v5 because app.mount is not used in many cases, and it's not so difficult to follow the new API.

So, please review this! If you have an opinion about the breaking change, feel free to share.

@yusukebe yusukebe removed the v5 label Oct 2, 2026
@usualoma

usualoma commented Oct 3, 2026

Copy link
Copy Markdown
Member

Thank you. LGTM!

@yusukebe

yusukebe commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

@usualoma Thanks!

@yusukebe
yusukebe merged commit ae595de into main Oct 4, 2026
19 checks passed
@yusukebe
yusukebe deleted the feat/mount-middleware branch October 4, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants