AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Turbopack HMR WebSocket Closure On First Load Breaks Initial Client-Side Navigation

In Next.js dev with Turbopack, the HMR WebSocket connection is closed before it is established, causing the first client-side navigation after a fresh page load to delay or fall back to a full page reload. After a manual reload, the connection succeeds and navigation works normally.

highConfidence 65%Next.jsReact Server ComponentsServer ActionsApp Router

Origin Analysis

The Turbopack HMR client sends initialization or ping messages before the WebSocket connection is fully open, causing the browser to close the socket with the error 'WebSocket is closed before the connection is established'. This prevents the client-side router from receiving the HMR ready signal, so the first navigation cannot complete as a client-side transition and instead triggers a full page load.
1. Clone the reproduction repository. 2. Run `npm install`. 3. Start `npm run dev` (default Turbopack). 4. Open the app in a new Chrome tab/private window. 5. Click a navigation link (e.g., `/about` or `/contact`). 6. Observe that the first navigation stalls or falls back to a full page load. 7. Reload the page once; navigation works normally. 8. Verify the issue does not occur with `next dev --webpack` or production build.

Fixing Code Block

Edge Case Audit

The pending message buffer could grow unbounded if the socket never opens (e.g., network failure). Add a maximum buffer size and a retry/backoff strategy. Test across Chrome, Firefox, and Safari; ensure no regression in hot reload updates. If issues arise, roll back this change and investigate server-side Turbopack HMR handshake ordering.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state