Files
Tim NeutkensandGitHub 89871864ed Rename /_next/webpack-hmr to /_next/hmr (#91415)
## What

Rename the HMR WebSocket path from `/_next/webpack-hmr` to `/_next/hmr`.

## Why

The `webpack-hmr` name is a leftover from when webpack was the only
bundler. Now that Turbopack is the default bundler for both `next dev`
and `next build`, the path name is misleading. The generic `/_next/hmr`
better reflects that this endpoint is bundler-agnostic.

## Changes

- **Client source** (`page-bootstrap.ts`, `web-socket.ts`): updated the
WebSocket connection path
- **Server** (`router-server.ts`): updated the HMR request detection
path
- **Turbopack** (`turbopack-dev-server/src/lib.rs`): updated the
fallback WebSocket path check
- **Tests**: updated all test files referencing the old path
- **Docs** (`version-12.mdx`): added a note that the path was renamed to
`/_next/hmr` in Next.js 16, while keeping the original v12 examples
intact
2026-03-19 16:39:45 +01:00

46 lines
951 B
TypeScript

declare global {
var _testState: {
initialized: boolean
reload: boolean | Promise<void>
}
}
if (!globalThis._testState) {
globalThis._testState = {
initialized: false,
reload: false,
}
}
export const subscribeToHMR = async () => {
const state = globalThis._testState
if (state.initialized) {
if (state.reload === true) {
let resolve: () => void
state.reload = new Promise<void>((res) => (resolve = res))
await new Promise((resolve) => setTimeout(resolve, 200))
resolve()
}
if (state.reload instanceof Promise) {
await state.reload
}
return
}
state.initialized = true
const ws = new WebSocket(`ws://localhost:${process.env.PORT}/_next/hmr`)
ws.onmessage = (event: any) => {
if (typeof event.data === 'string') {
const data = JSON.parse(event.data)
if (data.type === 'serverComponentChanges') {
state.reload = true
}
}
}
}