Skip to content

Fragment identifiers cause incorrect route parameter parsing in Service Worker #4440

@yatsuna827

Description

@yatsuna827

What version of Hono are you using?

4.9.9

What runtime/platform is your app running on? (with version if possible)

browser service worker (Chrome)

What steps can reproduce the bug?

1: Run Hono in a Service Worker context using fire() from hono/service-worker
2: Define routes

   app.get('/users/', (c) => c.html(...))
   app.get('/users/:id', (c) => c.html(...))

3: User navigates to the page with a fragment:

GET /users/#user-list
GET /users/1#profile-section

What is the expected behavior?

  • /users/#user-list matches /users/ route
  • /users/1#profile-section matches /users/:id route with id = "1"

What do you see instead?

  • /users/#user-list matches /users/:id route with id = "#user-list"
  • /users/1#profile-section matches /users/:id but with id = "1#profile-section"

This occurs because Service Workers receive the full URL including fragments, unlike traditional web servers where browsers strip fragments before sending requests. Hono's route matcher treats # as a regular character.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions