Skip to content

Releases: honojs/hono

v4.11.3

26 Dec 09:33

Choose a tag to compare

What's Changed

  • fix(types): fix middleware union type merging in MergeMiddlewareResponse by @yusukebe in #4602

Full Changelog: v4.11.2...v4.11.3

v4.11.2

25 Dec 10:41

Choose a tag to compare

What's Changed

  • docs: improve grammar in contributing documentation by @Ishiezz in #4581
  • fix(validator): preserve literal union types in input type inference by @yusukebe in #4583
  • chore: bump typescript-go preview for accurate benchmarking by @sushichan044 in #4586
  • refactor(hono-base): add type annotations by @yusukebe in #4591
  • refactor(client): refactor HonoURL types by @yusukebe in #4592
  • perf(types): reduce Simplify in ToSchema by @yusukebe in #4597
  • perf(types): optimize MergeMiddlewareResponse type by @yusukebe in #4598

New Contributors

Full Changelog: v4.11.1...v4.11.2

v4.11.1

14 Dec 22:14

Choose a tag to compare

What's Changed

  • fix(types): fix app.on method array type inference by @kosei28 in #4578

Full Changelog: v4.11.0...v4.11.1

v4.11.0

13 Dec 09:31

Choose a tag to compare

Release Notes

Hono v4.11.0 is now available!

This release includes new features for the Hono client, middleware improvements, and an important type system fix.

Type System Fix for Middleware

We've fixed a bug in the type system for middleware. Previously, app did not have the correct type with pathless handlers:

const app = new Hono()
  .use(async (c, next) => {
    await next()
  })
  .get('/a', async (c, next) => {
    await next()
  })
  .get((c) => {
    return c.text('Hello')
  })

// app's type was incorrect

This has now been fixed.

Thanks @kosei28!

Typed URL for Hono Client

You can now pass the base URL as the second type parameter to hc to get more precise URL types:

const client = hc<typeof app, 'http://localhost:8787'>(
  'http://localhost:8787/'
)

const url = client.api.posts.$url()
// url is TypedURL with precise type information
// including protocol, host, and path

This is useful when you want to use the URL as a type-safe key for libraries like SWR.

Thanks @miyaji255!

Custom NotFoundResponse Type

You can now customize the NotFoundResponse type using module augmentation. This allows c.notFound() to return a typed response:

import { Hono, TypedResponse } from 'hono'

declare module 'hono' {
  interface NotFoundResponse
    extends Response,
      TypedResponse<{ error: string }, 404, 'json'> {}
}

const app = new Hono()
  .get('/posts/:id', async (c) => {
    const post = await getPost(c.req.param('id'))
    if (!post) {
      return c.notFound()
    }
    return c.json({ post }, 200)
  })
  .notFound((c) => c.json({ error: 'not found' }, 404))

Now the client can correctly infer the 404 response type.

Thanks @miyaji255!

tryGetContext Helper

The new tryGetContext() helper in the Context Storage middleware returns undefined instead of throwing an error when the context is not available:

import { tryGetContext } from 'hono/context-storage'

const context = tryGetContext<Env>()
if (context) {
  // Context is available
  console.log(context.var.message)
}

Thanks @AyushCoder9!

Custom Query Serializer

You can now customize how query parameters are serialized using the buildSearchParams option:

const client = hc<AppType>('http://localhost', {
  buildSearchParams: (query) => {
    const searchParams = new URLSearchParams()
    for (const [k, v] of Object.entries(query)) {
      if (v === undefined) continue
      if (Array.isArray(v)) {
        v.forEach((item) => searchParams.append(`${k}[]`, item))
      } else {
        searchParams.set(k, v)
      }
    }
    return searchParams
  },
})

Thanks @bolasblack!

New features

  • feat(types): make Hono client's $url return the exact URL type #4502
  • feat(types): enhance NotFoundHandler to support custom NotFoundResponse type #4518
  • feat(timing): add wrapTime to simplify usage #4519
  • feat(pretty-json): support force option #4531
  • feat(client): add buildSearchParams option to customize query serialization #4535
  • feat(context-storage): add optional tryGetContext helper #4539
  • feat(secure-headers): add CSP report-to and report-uri directive support #4555
  • fix(types): replace schema-based path tracking with CurrentPath parameter #4552

All changes

  • chore: update esbuild to version 0.27.1 by @kosei28 in #4571
  • fix(hono/jsx): display blank when children is nullish by @techfish-11 in #4573
  • feat(types): make Hono client's $url return the exact URL type by @miyaji255 in #4502
  • feat(types): enhance NotFoundHandler to support custom NotFoundResponse type by @miyaji255 in #4518
  • feat(timing): add wrapTime to simplify usage by @PassiDel in #4519
  • feat(pretty-json): support force option by @missinglink in #4531
  • feat(context-storage): Add optional tryGetContext helper to context-storage middleware by @AyushCoder9 in #4539
  • feat(client): add buildSearchParams option to customize query serialization by @bolasblack in #4535
  • feat(secure-headers): Add CSP report-to and report-uri directive support by @cruzz77 in #4555
  • fix(types): replace schema-based path tracking with CurrentPath parameter by @kosei28 in #4552
  • Next by @yusukebe in #4574

New Contributors

Full Changelog: v4.10.8...v4.11.0

v4.10.8

09 Dec 08:26

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v4.10.7...v4.10.8

v4.10.7

26 Nov 11:40

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v4.10.6...v4.10.7

v4.10.6

14 Nov 14:34

Choose a tag to compare

Deperecated

bearer-auth options

The following options are deprecated and will be removed in a future version:

  • noAuthenticationHeaderMessage => use noAuthenticationHeader.message
  • invalidAuthenticationHeaderMessage => use invalidAuthenticationHeader.message
  • invalidTokenMessage => use invalidToken.message

What's Changed

New Contributors

Full Changelog: v4.10.5...v4.10.6

v4.10.5

11 Nov 12:14

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v4.10.4...v4.10.5

v4.10.4

30 Oct 01:20

Choose a tag to compare

What's Changed

  • chore: add a monochrome logo image by @yusukebe in #4487
  • chore: fix the monochrome logo by @yusukebe in #4488
  • fix(secure-headers): proposed features typo spelling mistake by @RosApr in #4494
  • fix(types): preserve handler response typing in createHandlers by @s-junio in #4492

New Contributors

Full Changelog: v4.10.3...v4.10.4

v4.10.3

24 Oct 17:04

Choose a tag to compare

Securiy Fix

A security issue in the CORS middleware has been fixed. In some cases, a request header could affect the Vary response header. Please update to the latest version if you are using the CORS middleware.

What's Changed

  • fix(aws-lambda): serve microsoft office files as binary in lambda handler by @matthiasfeist in #4469
  • fix(request-id): validation accepts = by @ryuapp in #4478
  • refactor(jwt): reduce the size of the code generated by minification by @usualoma in #4480

New Contributors

Full Changelog: v4.10.2...v4.10.3