From a1d530dfeb01304bc748ffb32e00d66b1c499093 Mon Sep 17 00:00:00 2001 From: Will Weiss Date: Tue, 26 May 2026 13:52:07 -0400 Subject: [PATCH 1/2] update docs to reflect the fact that websockets do not work with vite dev server --- docs/latest/advanced/websockets.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/latest/advanced/websockets.md b/docs/latest/advanced/websockets.md index cac0bc85450..b836604a2e2 100644 --- a/docs/latest/advanced/websockets.md +++ b/docs/latest/advanced/websockets.md @@ -6,6 +6,24 @@ description: | Fresh provides built-in helpers for upgrading HTTP connections to WebSockets. There are two main approaches depending on your use case. +> [warn]: WebSocket upgrades do not work under the Vite dev server (`deno task +> dev`). Both `app.ws()` and `ctx.upgrade()` rely on `Deno.upgradeWebSocket()`, +> which requires Deno's native HTTP server to be handling the request. Vite +> serves requests through a Node HTTP server and forwards them to Fresh as +> synthesized `Request` objects, so the 101 upgrade response cannot be +> completed and the `open` handler is never invoked. +> +> To test WebSocket endpoints locally, run a production-style build: +> +> ```sh +> deno task build && deno task start +> ``` +> +> This runs `deno serve` directly, so `Deno.upgradeWebSocket()` works as +> expected. If you need WebSockets during iterative development, run a +> separate Deno entry point (e.g. `deno serve -A main.ts`) alongside Vite, or +> host the WebSocket server as a sidecar on its own port. + ## Quick start with `app.ws()` The simplest way to add a WebSocket endpoint: From 70f8e6280b30445b6ccba9043aad12de31ac700c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 27 May 2026 07:36:16 +0200 Subject: [PATCH 2/2] docs: reflect that WS works in Vite dev on Fresh 2.4+ / Deno 2.8+ --- docs/latest/advanced/websockets.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/latest/advanced/websockets.md b/docs/latest/advanced/websockets.md index b836604a2e2..9ddb1499025 100644 --- a/docs/latest/advanced/websockets.md +++ b/docs/latest/advanced/websockets.md @@ -6,23 +6,23 @@ description: | Fresh provides built-in helpers for upgrading HTTP connections to WebSockets. There are two main approaches depending on your use case. -> [warn]: WebSocket upgrades do not work under the Vite dev server (`deno task -> dev`). Both `app.ws()` and `ctx.upgrade()` rely on `Deno.upgradeWebSocket()`, -> which requires Deno's native HTTP server to be handling the request. Vite -> serves requests through a Node HTTP server and forwards them to Fresh as -> synthesized `Request` objects, so the 101 upgrade response cannot be -> completed and the `open` handler is never invoked. +> [info]: WebSocket upgrades under the Vite dev server (`deno task dev`) require +> **Fresh 2.4+** and **Deno 2.8+**. On older versions `Deno.upgradeWebSocket()` +> cannot complete the 101 handshake for requests Vite forwards from its Node +> HTTP server, so `ctx.upgrade()` and `app.ws()` silently hang and the `open` +> handler is never invoked. > -> To test WebSocket endpoints locally, run a production-style build: +> If you're stuck on an older Deno or Fresh, exercise WebSocket endpoints with a +> production-style build instead: > > ```sh > deno task build && deno task start > ``` > > This runs `deno serve` directly, so `Deno.upgradeWebSocket()` works as -> expected. If you need WebSockets during iterative development, run a -> separate Deno entry point (e.g. `deno serve -A main.ts`) alongside Vite, or -> host the WebSocket server as a sidecar on its own port. +> expected. Alternatively, run a separate Deno entry point (e.g. +> `deno serve -A main.ts`) alongside Vite, or host the WebSocket server as a +> sidecar on its own port. ## Quick start with `app.ws()`