Skip to content

Commit 9f379f5

Browse files
committed
review feedback
1 parent f169701 commit 9f379f5

2 files changed

Lines changed: 26 additions & 27 deletions

File tree

packages/next/src/server/dev/hot-reloader-turbopack.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
processTopLevelIssues,
6060
printNonFatalIssue,
6161
normalizedPageToTurbopackStructureRoute,
62+
type StartChangeSubscription,
6263
} from './turbopack-utils'
6364
import {
6465
propagateServerField,
@@ -1081,10 +1082,20 @@ export async function createHotReloaderTurbopack(
10811082
// trailing /page or /route segment (e.g. "/page" for the root route,
10821083
// "/blog/[slug]/page" for a dynamic page). Use normalizeAppPath to
10831084
// strip that suffix and find the entry matching the user-facing route.
1084-
let appOriginalName: string | undefined
1085+
let extraOptions: object | undefined = undefined
10851086
for (const [name] of currentEntrypoints.app) {
10861087
if (normalizeAppPath(name) === page) {
1087-
appOriginalName = name
1088+
extraOptions = {
1089+
// Synthesize a definition so ensurePage bypasses findPagePathData.
1090+
// Only page and bundlePath are used from the definition:
1091+
// - page: the originalName used as the route key for currentEntrypoints lookup
1092+
// - bundlePath: must start with "app/" to set isInsideAppDir=true
1093+
definition: {
1094+
page: name,
1095+
bundlePath: `app${name}`,
1096+
filename: '',
1097+
} as any,
1098+
}
10881099
break
10891100
}
10901101
}
@@ -1098,19 +1109,7 @@ export async function createHotReloaderTurbopack(
10981109
// updates for routes compiled this way, and these subscriptions
10991110
// are never unsubscribed (see TODOs in handleRouteType).
11001111
subscribeToChanges: false,
1101-
...(appOriginalName
1102-
? {
1103-
// Synthesize a definition so ensurePage bypasses findPagePathData.
1104-
// Only page and bundlePath are used from the definition:
1105-
// - page: the originalName used as the route key for currentEntrypoints lookup
1106-
// - bundlePath: must start with "app/" to set isInsideAppDir=true
1107-
definition: {
1108-
page: appOriginalName,
1109-
bundlePath: `app${appOriginalName}`,
1110-
filename: '',
1111-
} as any,
1112-
}
1113-
: {}),
1112+
...extraOptions,
11141113
}
11151114

11161115
// Snapshot the current issue maps before compilation so we can
@@ -1798,11 +1797,11 @@ export async function createHotReloaderTurbopack(
17981797
logErrors: true,
17991798

18001799
hooks: {
1801-
// Omit subscribeToChanges to skip wiring HMR subscriptions for
1800+
// Pass a no-o subscribeToChanges to skip wiring HMR subscriptions for
18021801
// one-shot compilations (e.g. compile_route MCP tool).
1803-
...(subscribeToChanges
1804-
? { subscribeToChanges: subscribeToClientChanges }
1805-
: null),
1802+
subscribeToChanges: subscribeToChanges
1803+
? subscribeToClientChanges
1804+
: ((async () => {}) as StartChangeSubscription),
18061805
handleWrittenEndpoint: (id, result, forceDeleteCache) => {
18071806
currentWrittenEntrypoints.set(id, result)
18081807
assetMapper.setPathsForKey(id, result.clientPaths)

packages/next/src/server/dev/turbopack-utils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export type ClientStateMap = WeakMap<ws, ClientState>
139139
// is no client to receive updates and no unsubscribe path.
140140
type HandleRouteTypeHooks = {
141141
handleWrittenEndpoint: HandleWrittenEndpoint
142-
subscribeToChanges?: StartChangeSubscription
142+
subscribeToChanges: StartChangeSubscription
143143
}
144144

145145
export async function handleRouteType({
@@ -256,7 +256,7 @@ export async function handleRouteType({
256256
if (dev) {
257257
// TODO subscriptions should only be caused by the WebSocket connections
258258
// otherwise we don't known when to unsubscribe and this leaking
259-
hooks?.subscribeToChanges?.(
259+
hooks?.subscribeToChanges(
260260
serverKey,
261261
false,
262262
route.dataEndpoint,
@@ -275,7 +275,7 @@ export async function handleRouteType({
275275
}
276276
}
277277
)
278-
hooks?.subscribeToChanges?.(
278+
hooks?.subscribeToChanges(
279279
clientKey,
280280
false,
281281
route.htmlEndpoint,
@@ -292,7 +292,7 @@ export async function handleRouteType({
292292
}
293293
)
294294
if (entrypoints.global.document) {
295-
hooks?.subscribeToChanges?.(
295+
hooks?.subscribeToChanges(
296296
getEntryKey('pages', 'server', '_document'),
297297
false,
298298
entrypoints.global.document,
@@ -349,7 +349,7 @@ export async function handleRouteType({
349349
if (dev) {
350350
// TODO subscriptions should only be caused by the WebSocket connections
351351
// otherwise we don't known when to unsubscribe and this leaking
352-
hooks?.subscribeToChanges?.(
352+
hooks?.subscribeToChanges(
353353
key,
354354
true,
355355
route.rscEndpoint,
@@ -869,7 +869,7 @@ export async function handlePagesErrorRoute({
869869

870870
const writtenEndpoint = await entrypoints.global.app.writeToDisk()
871871
hooks.handleWrittenEndpoint(key, writtenEndpoint, false)
872-
hooks.subscribeToChanges?.(
872+
hooks.subscribeToChanges(
873873
key,
874874
false,
875875
entrypoints.global.app,
@@ -898,7 +898,7 @@ export async function handlePagesErrorRoute({
898898

899899
const writtenEndpoint = await entrypoints.global.document.writeToDisk()
900900
hooks.handleWrittenEndpoint(key, writtenEndpoint, false)
901-
hooks.subscribeToChanges?.(
901+
hooks.subscribeToChanges(
902902
key,
903903
false,
904904
entrypoints.global.document,
@@ -924,7 +924,7 @@ export async function handlePagesErrorRoute({
924924

925925
const writtenEndpoint = await entrypoints.global.error.writeToDisk()
926926
hooks.handleWrittenEndpoint(key, writtenEndpoint, false)
927-
hooks.subscribeToChanges?.(
927+
hooks.subscribeToChanges(
928928
key,
929929
false,
930930
entrypoints.global.error,

0 commit comments

Comments
 (0)