Unverified Commit 8b4bb031 authored by Justin Ridgewell's avatar Justin Ridgewell Committed by GitHub

Fixes for Turbopack HMR (#54790)

### What?

There were a few issues with the initial implementation of next-api HMR:
1. We incorrectly errored out when we received a Next.js WebSocket message
2. We didn't handle Next's `span-end` message, leading to another error
3. We listened to the `htmlEndpoint` change events instead of the `dataEndpoint`/`rscEndpoint`, leading to us detecting client-side changes and causing full page reloads

### Why?

HMR is the life-blood of development

### How?

Small fixes to our Turbopack reimplementation of the server-side HRM handlers

Closes WEB-1475
parent 7744aa26
...@@ -754,6 +754,7 @@ async function startWatcher(opts: SetupOpts) { ...@@ -754,6 +754,7 @@ async function startWatcher(opts: SetupOpts) {
case 'server-component-reload-page': // { clientId } case 'server-component-reload-page': // { clientId }
case 'client-reload-page': // { clientId } case 'client-reload-page': // { clientId }
case 'client-full-reload': // { stackTrace, hadRuntimeError } case 'client-full-reload': // { stackTrace, hadRuntimeError }
case 'span-end': // { startTime, endTime, spanName, attributes }
// TODO // TODO
break break
...@@ -775,7 +776,10 @@ async function startWatcher(opts: SetupOpts) { ...@@ -775,7 +776,10 @@ async function startWatcher(opts: SetupOpts) {
break break
default: default:
throw new Error(`unrecognized Turbopack HMR message "${data}"`) // Might have been a Next.js message...
if (!parsedData.event) {
throw new Error(`unrecognized Turbopack message "${data}"`)
}
} }
}) })
...@@ -886,7 +890,7 @@ async function startWatcher(opts: SetupOpts) { ...@@ -886,7 +890,7 @@ async function startWatcher(opts: SetupOpts) {
page, page,
await route.htmlEndpoint.writeToDisk() await route.htmlEndpoint.writeToDisk()
) )
changeSubscription(page, route.htmlEndpoint, (pageName, change) => { changeSubscription(page, route.dataEndpoint, (pageName, change) => {
switch (change) { switch (change) {
case ServerClientChangeType.Server: case ServerClientChangeType.Server:
case ServerClientChangeType.Both: case ServerClientChangeType.Both:
...@@ -939,7 +943,7 @@ async function startWatcher(opts: SetupOpts) { ...@@ -939,7 +943,7 @@ async function startWatcher(opts: SetupOpts) {
} }
case 'app-page': { case 'app-page': {
await processResult(page, await route.htmlEndpoint.writeToDisk()) await processResult(page, await route.htmlEndpoint.writeToDisk())
changeSubscription(page, route.htmlEndpoint, (_page, change) => { changeSubscription(page, route.rscEndpoint, (_page, change) => {
switch (change) { switch (change) {
case ServerClientChangeType.Server: case ServerClientChangeType.Server:
case ServerClientChangeType.Both: case ServerClientChangeType.Both:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment