Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serverError action to list of HMR events #54964

Merged
merged 6 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/src/client/page-bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function pageBootrap(assetPrefix: string) {
let buildIndicatorHandler: (obj: Record<string, any>) => void = () => {}

function devPagesHmrListener(payload: any) {
if (payload.action === 'serverError' && payload.errorJSON) {
if (payload.action === 'serverError') {
const { stack, message } = JSON.parse(payload.errorJSON)
const error = new Error(message)
error.stack = stack
Expand Down
7 changes: 7 additions & 0 deletions packages/next/src/server/dev/hot-reloader-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const enum HMR_ACTIONS_SENT_TO_BROWSER {
PONG = 'pong',
DEV_PAGES_MANIFEST_UPDATE = 'devPagesManifestUpdate',
TURBOPACK_MESSAGE = 'turbopack-message',
SERVER_ERROR = 'serverError',
}

interface ServerErrorAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ERROR
errorJSON: string
}

interface TurboPackMessageAction {
Expand Down Expand Up @@ -96,6 +102,7 @@ export type HMR_ACTION_TYPES =
| MiddlewareChangesAction
| ServerOnlyChangesAction
| DevPagesManifestUpdateAction
| ServerErrorAction

export interface NextJsHotReloaderInterface {
activeWebpackConfigs?: Array<Awaited<ReturnType<typeof getBaseWebpackConfig>>>
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/dev/hot-reloader-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,7 @@ export default class HotReloader implements NextJsHotReloaderInterface {
})

this.onDemandEntries = onDemandEntryHandler({
hotReloader: this,
multiCompiler: this.multiCompiler,
pagesDir: this.pagesDir,
appDir: this.appDir,
Expand Down
14 changes: 8 additions & 6 deletions packages/next/src/server/dev/on-demand-entry-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
} from '../../shared/lib/constants'
import { RouteMatch } from '../future/route-matches/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')

Expand Down Expand Up @@ -498,6 +500,7 @@ async function findRoutePathData(
}

export function onDemandEntryHandler({
hotReloader,
maxInactiveAge,
multiCompiler,
nextConfig,
Expand All @@ -506,6 +509,7 @@ export function onDemandEntryHandler({
rootDir,
appDir,
}: {
hotReloader: HotReloader
maxInactiveAge: number
multiCompiler: webpack.MultiCompiler
nextConfig: NextConfigComplete
Expand Down Expand Up @@ -947,12 +951,10 @@ export function onDemandEntryHandler({

// New error occurred: buffered error is flushed and new error occurred
if (!bufferedHmrServerError && error) {
client.send(
JSON.stringify({
action: 'serverError',
errorJSON: stringifyError(error),
})
)
hotReloader.send({
action: HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ERROR,
errorJSON: stringifyError(error),
})
bufferedHmrServerError = null
}

Expand Down
Loading