Unverified Commit 91922c44 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add serverError action to list of HMR events (#54964)

Adds `serverError` to the list of HMR actions, missed this in the earlier PRs as it wasn't using `hotReloader.send`.

Also ensures on-demand-entry-handler reuses the hotReloader.send method.
parent 986f648b
...@@ -17,7 +17,7 @@ export function pageBootrap(assetPrefix: string) { ...@@ -17,7 +17,7 @@ export function pageBootrap(assetPrefix: string) {
let buildIndicatorHandler: (obj: Record<string, any>) => void = () => {} let buildIndicatorHandler: (obj: Record<string, any>) => void = () => {}
function devPagesHmrListener(payload: any) { function devPagesHmrListener(payload: any) {
if (payload.action === 'serverError' && payload.errorJSON) { if (payload.action === 'serverError') {
const { stack, message } = JSON.parse(payload.errorJSON) const { stack, message } = JSON.parse(payload.errorJSON)
const error = new Error(message) const error = new Error(message)
error.stack = stack error.stack = stack
......
...@@ -18,6 +18,12 @@ export const enum HMR_ACTIONS_SENT_TO_BROWSER { ...@@ -18,6 +18,12 @@ export const enum HMR_ACTIONS_SENT_TO_BROWSER {
PONG = 'pong', PONG = 'pong',
DEV_PAGES_MANIFEST_UPDATE = 'devPagesManifestUpdate', DEV_PAGES_MANIFEST_UPDATE = 'devPagesManifestUpdate',
TURBOPACK_MESSAGE = 'turbopack-message', TURBOPACK_MESSAGE = 'turbopack-message',
SERVER_ERROR = 'serverError',
}
interface ServerErrorAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ERROR
errorJSON: string
} }
interface TurboPackMessageAction { interface TurboPackMessageAction {
...@@ -96,6 +102,7 @@ export type HMR_ACTION_TYPES = ...@@ -96,6 +102,7 @@ export type HMR_ACTION_TYPES =
| MiddlewareChangesAction | MiddlewareChangesAction
| ServerOnlyChangesAction | ServerOnlyChangesAction
| DevPagesManifestUpdateAction | DevPagesManifestUpdateAction
| ServerErrorAction
export interface NextJsHotReloaderInterface { export interface NextJsHotReloaderInterface {
activeWebpackConfigs?: Array<Awaited<ReturnType<typeof getBaseWebpackConfig>>> activeWebpackConfigs?: Array<Awaited<ReturnType<typeof getBaseWebpackConfig>>>
......
...@@ -1385,6 +1385,7 @@ export default class HotReloader implements NextJsHotReloaderInterface { ...@@ -1385,6 +1385,7 @@ export default class HotReloader implements NextJsHotReloaderInterface {
}) })
this.onDemandEntries = onDemandEntryHandler({ this.onDemandEntries = onDemandEntryHandler({
hotReloader: this,
multiCompiler: this.multiCompiler, multiCompiler: this.multiCompiler,
pagesDir: this.pagesDir, pagesDir: this.pagesDir,
appDir: this.appDir, appDir: this.appDir,
......
...@@ -35,6 +35,8 @@ import { ...@@ -35,6 +35,8 @@ import {
} from '../../shared/lib/constants' } from '../../shared/lib/constants'
import { RouteMatch } from '../future/route-matches/route-match' import { RouteMatch } from '../future/route-matches/route-match'
import { isAppPageRouteMatch } from '../future/route-matches/app-page-route-match' import { isAppPageRouteMatch } from '../future/route-matches/app-page-route-match'
import { HMR_ACTIONS_SENT_TO_BROWSER } from './hot-reloader-types'
import HotReloader from './hot-reloader-webpack'
const debug = origDebug('next:on-demand-entry-handler') const debug = origDebug('next:on-demand-entry-handler')
...@@ -498,6 +500,7 @@ async function findRoutePathData( ...@@ -498,6 +500,7 @@ async function findRoutePathData(
} }
export function onDemandEntryHandler({ export function onDemandEntryHandler({
hotReloader,
maxInactiveAge, maxInactiveAge,
multiCompiler, multiCompiler,
nextConfig, nextConfig,
...@@ -506,6 +509,7 @@ export function onDemandEntryHandler({ ...@@ -506,6 +509,7 @@ export function onDemandEntryHandler({
rootDir, rootDir,
appDir, appDir,
}: { }: {
hotReloader: HotReloader
maxInactiveAge: number maxInactiveAge: number
multiCompiler: webpack.MultiCompiler multiCompiler: webpack.MultiCompiler
nextConfig: NextConfigComplete nextConfig: NextConfigComplete
...@@ -947,12 +951,10 @@ export function onDemandEntryHandler({ ...@@ -947,12 +951,10 @@ export function onDemandEntryHandler({
// New error occurred: buffered error is flushed and new error occurred // New error occurred: buffered error is flushed and new error occurred
if (!bufferedHmrServerError && error) { if (!bufferedHmrServerError && error) {
client.send( hotReloader.send({
JSON.stringify({ action: HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ERROR,
action: 'serverError', errorJSON: stringifyError(error),
errorJSON: stringifyError(error), })
})
)
bufferedHmrServerError = null bufferedHmrServerError = null
} }
......
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