-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Implement hot-reloader interface #54629
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { IncomingMessage, ServerResponse } from 'http' | ||
import type { UrlObject } from 'url' | ||
import type { Duplex } from 'stream' | ||
import type { webpack } from 'next/dist/compiled/webpack/webpack' | ||
import type getBaseWebpackConfig from '../../build/webpack-config' | ||
import type { RouteMatch } from '../future/route-matches/route-match' | ||
|
||
export interface NextJsHotReloaderInterface { | ||
activeConfigs?: Array<Awaited<ReturnType<typeof getBaseWebpackConfig>>> | ||
serverStats: webpack.Stats | null | ||
edgeServerStats: webpack.Stats | null | ||
run( | ||
req: IncomingMessage, | ||
res: ServerResponse, | ||
parsedUrl: UrlObject | ||
): Promise<{ finished?: true }> | ||
|
||
setHmrServerError(error: Error | null): void | ||
clearHmrServerError(): void | ||
start(): Promise<void> | ||
stop(): Promise<void> | ||
send(action?: string | any, ...args: any[]): void | ||
getCompilationErrors(page: string): Promise<any[]> | ||
onHMR(req: IncomingMessage, _socket: Duplex, head: Buffer): void | ||
invalidate({ | ||
reloadAfterInvalidation, | ||
}: { | ||
reloadAfterInvalidation: boolean | ||
}): void | ||
buildFallbackError(): Promise<void> | ||
ensurePage({ | ||
page, | ||
clientOnly, | ||
appPaths, | ||
match, | ||
isApp, | ||
}: { | ||
page: string | ||
clientOnly: boolean | ||
appPaths?: string[] | null | ||
isApp?: boolean | ||
match?: RouteMatch | ||
}): Promise<void> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ import type { NextConfigComplete } from '../config-shared' | |
import type { CustomRoutes } from '../../lib/load-custom-routes' | ||
import type { Duplex } from 'stream' | ||
import type { Telemetry } from '../../telemetry/storage' | ||
import type { IncomingMessage, ServerResponse } from 'http' | ||
import type { UrlObject } from 'url' | ||
|
||
import { webpack, StringXor } from 'next/dist/compiled/webpack/webpack' | ||
import { getOverlayMiddleware } from 'next/dist/compiled/@next/react-dev-overlay/dist/middleware' | ||
import { IncomingMessage, ServerResponse } from 'http' | ||
import { WebpackHotMiddleware } from './hot-middleware' | ||
import { join, relative, isAbsolute, posix } from 'path' | ||
import { UrlObject } from 'url' | ||
import { | ||
createEntrypoints, | ||
createPagesMapping, | ||
|
@@ -67,6 +67,7 @@ import { isAPIRoute } from '../../lib/is-api-route' | |
import { getRouteLoaderEntry } from '../../build/webpack/loaders/next-route-loader' | ||
import { isInternalComponent } from '../../lib/is-internal-component' | ||
import { RouteKind } from '../future/route-kind' | ||
import { NextJsHotReloaderInterface } from './hot-reloader-types' | ||
|
||
const MILLISECONDS_IN_NANOSECOND = 1_000_000 | ||
|
||
|
@@ -174,7 +175,7 @@ function erroredPages(compilation: webpack.Compilation) { | |
return failedPages | ||
} | ||
|
||
export default class HotReloader { | ||
export default class HotReloader implements NextJsHotReloaderInterface { | ||
private hasAmpEntrypoints: boolean | ||
private hasAppRouterEntrypoints: boolean | ||
private hasPagesRouterEntrypoints: boolean | ||
|
@@ -185,10 +186,7 @@ export default class HotReloader { | |
private distDir: string | ||
private webpackHotMiddleware?: WebpackHotMiddleware | ||
private config: NextConfigComplete | ||
public hasServerComponents: boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found this variable was not used so removed it 👍 |
||
public clientStats: webpack.Stats | null | ||
public serverStats: webpack.Stats | null | ||
public edgeServerStats: webpack.Stats | null | ||
private clientStats: webpack.Stats | null | ||
private clientError: Error | null = null | ||
private serverError: Error | null = null | ||
private hmrServerError: Error | null = null | ||
|
@@ -209,6 +207,9 @@ export default class HotReloader { | |
installed: '0.0.0', | ||
} | ||
private reloadAfterInvalidation: boolean = false | ||
|
||
public serverStats: webpack.Stats | null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the public variables together so that they're easier to spot. |
||
public edgeServerStats: webpack.Stats | null | ||
public multiCompiler?: webpack.MultiCompiler | ||
public activeConfigs?: Array< | ||
UnwrapPromise<ReturnType<typeof getBaseWebpackConfig>> | ||
|
@@ -252,7 +253,6 @@ export default class HotReloader { | |
this.telemetry = telemetry | ||
|
||
this.config = config | ||
this.hasServerComponents = !!this.appDir | ||
this.previewProps = previewProps | ||
this.rewrites = rewrites | ||
this.hotReloaderSpan = trace('hot-reloader', undefined, { | ||
|
@@ -346,7 +346,7 @@ export default class HotReloader { | |
} | ||
} | ||
|
||
public async refreshServerComponents(): Promise<void> { | ||
protected async refreshServerComponents(): Promise<void> { | ||
this.send({ | ||
action: 'serverComponentChanges', | ||
// TODO: granular reloading of changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webpack.Stats is probably hard to implemented for non webpack implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only used in
logErrorWithOriginalStack
, we'll want to replace the usage ofserverStats
andedgeServerStats
for this.