Skip to content

fix(client): normalize root WebSocket URLs - #5291

Open
Ersaoktaviannn wants to merge 1 commit into
honojs:mainfrom
Ersaoktaviannn:fix/client-ws-root-index
Open

fix(client): normalize root WebSocket URLs#5291
Ersaoktaviannn wants to merge 1 commit into
honojs:mainfrom
Ersaoktaviannn:fix/client-ws-root-index

Conversation

@Ersaoktaviannn

Copy link
Copy Markdown
Contributor

Summary

  • normalize the Hono Client index alias before constructing WebSocket URLs
  • keep protocol translation, query serialization, and custom WebSocket providers unchanged
  • preserve real path parameter values equal to index

Before / after

Typed route Before After
client.index.$ws() for / ws://host/index ws://host/
nested root route ws://host/api/index ws://host/api
/:id with id: "index" ws://host/index unchanged

Impact

index is the client-side alias for a root route. $get(), $url(), and $path() already remove that synthetic segment, but $ws() did not. As a result, a typed WebSocket client for / attempted its handshake against /index (and a nested root against /api/index), which targets a different route and commonly returns 404.

Normalization runs before path parameter substitution, so a genuine dynamic value named index is not removed.

Verification

  • npx vitest --run src/client/client.test.ts — 119 passed
  • npx vitest --run src/client/types.test.ts --coverage.enabled=false — 13 passed
  • npx tsc -p tsconfig.spec.json --pretty false
  • Prettier, ESLint, and git diff --check on the changed files

The author should do the following, if applicable

  • Add tests
  • Run focused tests and type checking
  • Format and lint the changed files
  • Add TSDoc/JSDoc — no public API added

The index segment is a client-side alias for root routes. Apply the existing normalization before path parameter substitution so $ws() targets the declared endpoint while preserving dynamic values named index.
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.

1 participant