Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
6a93d710
Commit
6a93d710
authored
Mar 20, 2026
by
Will Binns-Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
1c5680e9
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
273 additions
and
26 deletions
+273
-26
hot-reloader-turbopack.ts
packages/next/src/server/dev/hot-reloader-turbopack.ts
+26
-8
turbopack-utils.ts
packages/next/src/server/dev/turbopack-utils.ts
+26
-0
instrumentation-globals.external.ts
...rver/lib/router-utils/instrumentation-globals.external.ts
+7
-0
layout.tsx
...nt/app-dir/server-hmr/app/segment-accept/inner/layout.tsx
+21
-0
page.tsx
...ment/app-dir/server-hmr/app/segment-accept/inner/page.tsx
+5
-0
segment-util.ts
...p-dir/server-hmr/app/segment-accept/inner/segment-util.ts
+2
-0
layout.tsx
...elopment/app-dir/server-hmr/app/segment-accept/layout.tsx
+15
-0
proxy-dep.ts
test/development/app-dir/server-hmr/proxy-dep.ts
+0
-0
proxy.ts
test/development/app-dir/server-hmr/proxy.ts
+1
-2
server-hmr.test.ts
test/development/app-dir/server-hmr/server-hmr.test.ts
+103
-2
hmr-client.ts
...bopack-ecmascript-runtime/js/src/nodejs/dev/hmr-client.ts
+22
-0
hmr-runtime.ts
...k-ecmascript-runtime/js/src/shared/runtime/hmr-runtime.ts
+45
-14
No files found.
packages/next/src/server/dev/hot-reloader-turbopack.ts
View file @
6a93d710
...
@@ -65,6 +65,7 @@ import {
...
@@ -65,6 +65,7 @@ import {
type
ServerFields
,
type
ServerFields
,
type
SetupOpts
,
type
SetupOpts
,
}
from
'../lib/router-utils/setup-dev-bundler'
}
from
'../lib/router-utils/setup-dev-bundler'
import
{
resetInstrumentationCache
}
from
'../lib/router-utils/instrumentation-globals.external'
import
{
TurbopackManifestLoader
}
from
'../../shared/lib/turbopack/manifest-loader'
import
{
TurbopackManifestLoader
}
from
'../../shared/lib/turbopack/manifest-loader'
import
{
findPagePathData
}
from
'./on-demand-entry-handler'
import
{
findPagePathData
}
from
'./on-demand-entry-handler'
import
type
{
RouteDefinition
}
from
'../route-definitions/route-definition'
import
type
{
RouteDefinition
}
from
'../route-definitions/route-definition'
...
@@ -616,24 +617,41 @@ export async function createHotReloaderTurbopack(
...
@@ -616,24 +617,41 @@ export async function createHotReloaderTurbopack(
entryPage
===
'instrumentation.nodeJs'
)))
&&
entryPage
===
'instrumentation.nodeJs'
)))
&&
writtenEndpoint
.
type
!==
'edge'
writtenEndpoint
.
type
!==
'edge'
// Root entries (middleware/instrumentation) are loaded via require() rather
// than __turbopack_require__. Their entry chunk's exports are cached in
// Node's require.cache and must be cleared when the module changes so that
// the next require() loads the updated code. Dep chunks are preserved so
// that unmodified deps are not re-evaluated.
const
isRootEntryChunk
=
usesServerHmr
&&
writtenEndpoint
.
type
===
'nodejs'
&&
entryType
===
'root'
const
filesToDelete
:
string
[]
=
[]
const
filesToDelete
:
string
[]
=
[]
for
(
const
file
of
serverPaths
)
{
for
(
const
file
of
serverPaths
)
{
clearModuleContext
(
file
)
clearModuleContext
(
file
)
const
relativePath
=
relative
(
distDir
,
file
)
const
relativePath
=
relative
(
distDir
,
file
)
if
(
const
inSubscriptions
=
!!
serverHmrSubscriptions
?.
has
(
relativePath
)
// For Pages Router, edge routes, middleware, and manifest files:
const
isEntryChunk
=
// clear the sharedCache in evalManifest(), Node.js require.cache,
isRootEntryChunk
&&
relativePath
===
writtenEndpoint
.
entryPath
// and edge runtime module contexts.
force
||
if
(
force
||
!
usesServerHmr
||
!
inSubscriptions
||
isEntryChunk
)
{
!
usesServerHmr
||
!
serverHmrSubscriptions
?.
has
(
relativePath
)
)
{
filesToDelete
.
push
(
file
)
filesToDelete
.
push
(
file
)
}
}
}
}
deleteCache
(
filesToDelete
)
deleteCache
(
filesToDelete
)
// Reset the instrumentation module cache so the next request re-requires
// the updated instrumentation module and re-runs its module-scope globals.
if
(
entryPage
===
'instrumentation.nodeJs'
)
{
resetInstrumentationCache
()
}
if
(
entryType
===
'root'
&&
writtenEndpoint
.
type
===
'nodejs'
)
{
console
.
log
(
`[dbg-root] key=
${
entryPage
}
entryPath=
${
writtenEndpoint
.
entryPath
}
filesToDelete=
${
filesToDelete
.
map
(
f
=>
relative
(
distDir
,
f
)).
join
(
','
)}
`
)
}
// Reset the fetch patch so patchFetch() can re-wrap on the next request.
// Reset the fetch patch so patchFetch() can re-wrap on the next request.
if
(
serverPaths
.
length
>
0
)
{
if
(
serverPaths
.
length
>
0
)
{
resetFetch
()
resetFetch
()
...
...
packages/next/src/server/dev/turbopack-utils.ts
View file @
6a93d710
...
@@ -512,6 +512,8 @@ export function hasEntrypointForKey(
...
@@ -512,6 +512,8 @@ export function hasEntrypointForKey(
case
'middleware'
:
case
'middleware'
:
return
entrypoints
.
global
.
middleware
!=
null
return
entrypoints
.
global
.
middleware
!=
null
case
'instrumentation'
:
case
'instrumentation'
:
case
'instrumentation.nodeJs'
:
case
'instrumentation.edge'
:
return
entrypoints
.
global
.
instrumentation
!=
null
return
entrypoints
.
global
.
instrumentation
!=
null
default
:
default
:
return
false
return
false
...
@@ -686,6 +688,30 @@ export async function handleEntrypoints({
...
@@ -686,6 +688,30 @@ export async function handleEntrypoints({
'actualInstrumentationHookFile'
,
'actualInstrumentationHookFile'
,
dev
.
serverFields
.
actualInstrumentationHookFile
dev
.
serverFields
.
actualInstrumentationHookFile
)
)
// Subscribe to instrumentation endpoint changes so server HMR picks up
// instrumentation module updates without a full server restart.
const
subscribeInstrumentation
=
(
name
:
string
,
prop
:
'nodeJs'
|
'edge'
)
=>
{
const
key
=
getEntryKey
(
'root'
,
'server'
,
name
)
dev
.
hooks
.
subscribeToChanges
(
key
,
false
,
instrumentation
[
prop
],
()
=>
{
void
processInstrumentation
(
name
,
prop
).
then
(()
=>
{
manifestLoader
.
loadMiddlewareManifest
(
'instrumentation'
,
'instrumentation'
)
manifestLoader
.
writeManifests
({
devRewrites
,
productionRewrites
:
undefined
,
entrypoints
:
currentEntrypoints
,
})
})
})
}
subscribeInstrumentation
(
'instrumentation.nodeJs'
,
'nodeJs'
)
subscribeInstrumentation
(
'instrumentation.edge'
,
'edge'
)
}
else
{
}
else
{
dev
.
serverFields
.
actualInstrumentationHookFile
=
undefined
dev
.
serverFields
.
actualInstrumentationHookFile
=
undefined
await
dev
.
hooks
.
propagateServerField
(
await
dev
.
hooks
.
propagateServerField
(
...
...
packages/next/src/server/lib/router-utils/instrumentation-globals.external.ts
View file @
6a93d710
...
@@ -79,6 +79,13 @@ export async function instrumentationOnRequestError(
...
@@ -79,6 +79,13 @@ export async function instrumentationOnRequestError(
}
}
let
registerInstrumentationPromise
:
Promise
<
void
>
|
null
=
null
let
registerInstrumentationPromise
:
Promise
<
void
>
|
null
=
null
export
function
resetInstrumentationCache
()
{
cachedInstrumentationModule
=
undefined
as
unknown
as
InstrumentationModule
instrumentationModulePromise
=
null
registerInstrumentationPromise
=
null
}
export
function
ensureInstrumentationRegistered
(
export
function
ensureInstrumentationRegistered
(
projectDir
:
string
,
projectDir
:
string
,
distDir
:
string
distDir
:
string
...
...
test/development/app-dir/server-hmr/app/segment-accept/inner/layout.tsx
0 → 100644
View file @
6a93d710
import
{
ReactNode
}
from
'react'
import
{
segmentUtilEvaluatedAt
}
from
'./segment-util'
export
const
_hmrTrigger
=
0
// Captured at module evaluation time — used by tests to detect re-evaluation
export
const
innerLayoutEvaluatedAt
=
Date
.
now
()
export
default
function
InnerLayout
({
children
}:
{
children
:
ReactNode
})
{
return
(
<
div
>
<
p
id=
"inner-layout-eval-time"
>
Inner Layout Evaluated At:
{
innerLayoutEvaluatedAt
}
</
p
>
<
p
id=
"segment-util-eval-time"
>
Segment Util Evaluated At:
{
segmentUtilEvaluatedAt
}
</
p
>
{
children
}
</
div
>
)
}
test/development/app-dir/server-hmr/app/segment-accept/inner/page.tsx
0 → 100644
View file @
6a93d710
export
const
_hmrTrigger
=
0
export
default
function
InnerPage
()
{
return
<
p
id=
"inner-page"
>
Inner Page
</
p
>
}
test/development/app-dir/server-hmr/app/segment-accept/inner/segment-util.ts
0 → 100644
View file @
6a93d710
export
const
_hmrTrigger
=
0
export
const
segmentUtilEvaluatedAt
=
Date
.
now
()
test/development/app-dir/server-hmr/app/segment-accept/layout.tsx
0 → 100644
View file @
6a93d710
import
{
ReactNode
}
from
'react'
// Captured at module evaluation time — used by tests to detect re-evaluation
export
const
outerLayoutEvaluatedAt
=
Date
.
now
()
export
default
function
OuterLayout
({
children
}:
{
children
:
ReactNode
})
{
return
(
<
div
>
<
p
id=
"outer-layout-eval-time"
>
Outer Layout Evaluated At:
{
outerLayoutEvaluatedAt
}
</
p
>
{
children
}
</
div
>
)
}
test/development/app-dir/server-hmr/
middleware
-dep.ts
→
test/development/app-dir/server-hmr/
proxy
-dep.ts
View file @
6a93d710
File moved
test/development/app-dir/server-hmr/
middleware
.ts
→
test/development/app-dir/server-hmr/
proxy
.ts
View file @
6a93d710
export
const
runtime
=
'nodejs'
import
{
NextResponse
}
from
'next/server'
import
{
NextResponse
}
from
'next/server'
import
{
depEvaluatedAt
}
from
'./
middleware
-dep'
import
{
depEvaluatedAt
}
from
'./
proxy
-dep'
export
default
function
middleware
()
{
export
default
function
middleware
()
{
const
res
=
NextResponse
.
next
()
const
res
=
NextResponse
.
next
()
...
...
test/development/app-dir/server-hmr/server-hmr.test.ts
View file @
6a93d710
...
@@ -160,7 +160,7 @@ describe('server-hmr', () => {
...
@@ -160,7 +160,7 @@ describe('server-hmr', () => {
const
initial
=
await
next
.
fetch
(
'/api/hello'
)
const
initial
=
await
next
.
fetch
(
'/api/hello'
)
expect
(
initial
.
headers
.
get
(
'x-middleware-version'
)).
toBe
(
'0'
)
expect
(
initial
.
headers
.
get
(
'x-middleware-version'
)).
toBe
(
'0'
)
await
next
.
patchFile
(
'
middleware
.ts'
,
(
content
)
=>
await
next
.
patchFile
(
'
proxy
.ts'
,
(
content
)
=>
content
.
replace
(
"'0'"
,
"'1'"
)
content
.
replace
(
"'0'"
,
"'1'"
)
)
)
...
@@ -182,7 +182,7 @@ describe('server-hmr', () => {
...
@@ -182,7 +182,7 @@ describe('server-hmr', () => {
expect
(
initialDepEvaluatedAt
).
toMatch
(
/^
\d
+$/
)
expect
(
initialDepEvaluatedAt
).
toMatch
(
/^
\d
+$/
)
// Change only the middleware, not the dependency
// Change only the middleware, not the dependency
await
next
.
patchFile
(
'
middleware
.ts'
,
(
content
)
=>
await
next
.
patchFile
(
'
proxy
.ts'
,
(
content
)
=>
content
.
replace
(
`'
${
initialVersion
}
'`
,
`'
${
initialVersion
}
-updated'`
)
content
.
replace
(
`'
${
initialVersion
}
'`
,
`'
${
initialVersion
}
-updated'`
)
)
)
...
@@ -251,6 +251,107 @@ describe('server-hmr', () => {
...
@@ -251,6 +251,107 @@ describe('server-hmr', () => {
)
)
})
})
describe
(
'segment-level accept'
,
()
=>
{
// Renders /segment-accept/inner which has two nested layouts:
// OuterLayout (app/segment-accept/layout.tsx) and
// InnerLayout (app/segment-accept/inner/layout.tsx)
itTurbopackDev
(
'does not re-evaluate outer layout when inner layout changes'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/segment-accept/inner'
)
// Wait for initial render
await
retry
(
async
()
=>
{
const
text
=
await
browser
.
elementByCss
(
'#outer-layout-eval-time'
)
.
text
()
expect
(
text
).
toMatch
(
/Outer Layout Evaluated At:
\d
+/
)
})
const
initialOuterEvalTime
=
await
browser
.
elementByCss
(
'#outer-layout-eval-time'
)
.
text
()
const
initialInnerEvalTime
=
await
browser
.
elementByCss
(
'#inner-layout-eval-time'
)
.
text
()
// Change the inner layout — only it should be re-evaluated
await
next
.
patchFile
(
'app/segment-accept/inner/layout.tsx'
,
(
content
)
=>
content
.
replace
(
'_hmrTrigger = 0'
,
'_hmrTrigger = 1'
)
)
// Wait until the inner layout is re-evaluated (its timestamp changes)
await
retry
(
async
()
=>
{
await
browser
.
refresh
()
const
newInnerEvalTime
=
await
browser
.
elementByCss
(
'#inner-layout-eval-time'
)
.
text
()
expect
(
newInnerEvalTime
).
not
.
toBe
(
initialInnerEvalTime
)
})
// The outer layout should NOT have been re-evaluated
const
newOuterEvalTime
=
await
browser
.
elementByCss
(
'#outer-layout-eval-time'
)
.
text
()
expect
(
newOuterEvalTime
).
toBe
(
initialOuterEvalTime
)
}
)
itTurbopackDev
(
're-evaluates inner layout but not outer when inner segment utility changes'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/segment-accept/inner'
)
// Wait for initial render
await
retry
(
async
()
=>
{
const
text
=
await
browser
.
elementByCss
(
'#outer-layout-eval-time'
)
.
text
()
expect
(
text
).
toMatch
(
/Outer Layout Evaluated At:
\d
+/
)
})
const
initialOuterEvalTime
=
await
browser
.
elementByCss
(
'#outer-layout-eval-time'
)
.
text
()
const
initialInnerEvalTime
=
await
browser
.
elementByCss
(
'#inner-layout-eval-time'
)
.
text
()
const
initialUtilEvalTime
=
await
browser
.
elementByCss
(
'#segment-util-eval-time'
)
.
text
()
// Change the utility imported by the inner layout.
// The inner layout is the nearest segment boundary, so both the utility
// and the inner layout should be re-evaluated. The outer layout should not.
await
next
.
patchFile
(
'app/segment-accept/inner/segment-util.ts'
,
(
content
)
=>
content
.
replace
(
'_hmrTrigger = 0'
,
'_hmrTrigger = 1'
)
)
// Wait until both the utility and inner layout are re-evaluated
await
retry
(
async
()
=>
{
await
browser
.
refresh
()
const
newUtilEvalTime
=
await
browser
.
elementByCss
(
'#segment-util-eval-time'
)
.
text
()
expect
(
newUtilEvalTime
).
not
.
toBe
(
initialUtilEvalTime
)
const
newInnerEvalTime
=
await
browser
.
elementByCss
(
'#inner-layout-eval-time'
)
.
text
()
expect
(
newInnerEvalTime
).
not
.
toBe
(
initialInnerEvalTime
)
})
// The outer layout should NOT have been re-evaluated
const
newOuterEvalTime
=
await
browser
.
elementByCss
(
'#outer-layout-eval-time'
)
.
text
()
expect
(
newOuterEvalTime
).
toBe
(
initialOuterEvalTime
)
}
)
})
describe
(
'route handler hmr'
,
()
=>
{
describe
(
'route handler hmr'
,
()
=>
{
function
getText
(
res
:
Response
)
{
function
getText
(
res
:
Response
)
{
return
res
.
ok
return
res
.
ok
...
...
turbopack/crates/turbopack-ecmascript-runtime/js/src/nodejs/dev/hmr-client.ts
View file @
6a93d710
...
@@ -73,6 +73,25 @@ function emitMessage(msg: { type: string; data: any }): boolean {
...
@@ -73,6 +73,25 @@ function emitMessage(msg: { type: string; data: any }): boolean {
}
}
}
}
/**
* App Router segment boundary files are natural HMR accept boundaries.
* The route entry loads them dynamically via __next_app_require__ on each
* server request, so it does not need re-instantiation when a segment changes.
* Only the segment file itself (and any transitive dependencies that don't
* self-accept) will be re-instantiated.
*
* Segment boundary files are identified by their conventional filenames inside
* the `app/` directory:
* layout, page, template, error, loading, not-found, forbidden, unauthorized,
* global-error, global-not-found
*/
const
SEGMENT_BOUNDARY_MODULE_RE
=
/
[/\\]
app
[/\\]
.*
[/\\](
layout|page|template|error|loading|not-found|forbidden|unauthorized|global-error|global-not-found
)\.[
jt
]
sx
?(\?
|$
)
/
function
isAppRouterSegmentModule
(
moduleId
:
ModuleId
):
boolean
{
return
SEGMENT_BOUNDARY_MODULE_RE
.
test
(
String
(
moduleId
))
}
/**
/**
* Handles server message updates and applies them to the Node.js runtime.
* Handles server message updates and applies them to the Node.js runtime.
* Uses shared HMR update logic from hmr-runtime.ts.
* Uses shared HMR update logic from hmr-runtime.ts.
...
@@ -116,6 +135,9 @@ function handleNodejsUpdate(
...
@@ -116,6 +135,9 @@ function handleNodejsUpdate(
moduleFactories
,
moduleFactories
,
devModuleCache
,
devModuleCache
,
autoAcceptRootModules
:
true
,
autoAcceptRootModules
:
true
,
// App Router segment files are accept boundaries: the update bubble stops
// at the segment rather than propagating all the way to the route entry.
isAutoAcceptModule
:
isAppRouterSegmentModule
,
})
})
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
error
(
'[Server HMR] Update failed, full reload needed:'
,
e
)
console
.
error
(
'[Server HMR] Update failed, full reload needed:'
,
e
)
...
...
turbopack/crates/turbopack-ecmascript-runtime/js/src/shared/runtime/hmr-runtime.ts
View file @
6a93d710
...
@@ -112,10 +112,14 @@ function formatDependencyChain(dependencyChain: ModuleId[]): string {
...
@@ -112,10 +112,14 @@ function formatDependencyChain(dependencyChain: ModuleId[]): string {
* @param moduleId - The module that changed
* @param moduleId - The module that changed
* @param autoAcceptRootModules - If true, root modules auto-accept updates without explicit module.hot.accept().
* @param autoAcceptRootModules - If true, root modules auto-accept updates without explicit module.hot.accept().
* This is used for server-side HMR where pages auto-accept at the top level.
* This is used for server-side HMR where pages auto-accept at the top level.
* @param isAutoAcceptModule - Optional predicate. If provided and returns true for a module ID, that module
* acts as an HMR accept boundary regardless of its hot.accept() state.
* Use this to define coarser accept boundaries (e.g. segment files in App Router).
*/
*/
function
getAffectedModuleEffects
(
function
getAffectedModuleEffects
(
moduleId
:
ModuleId
,
moduleId
:
ModuleId
,
autoAcceptRootModules
:
boolean
autoAcceptRootModules
:
boolean
,
isAutoAcceptModule
?:
(
moduleId
:
ModuleId
)
=>
boolean
):
ModuleEffect
{
):
ModuleEffect
{
const
outdatedModules
:
Set
<
ModuleId
>
=
new
Set
()
const
outdatedModules
:
Set
<
ModuleId
>
=
new
Set
()
const
outdatedDependencies
:
Map
<
ModuleId
,
Set
<
ModuleId
>>
=
new
Map
()
const
outdatedDependencies
:
Map
<
ModuleId
,
Set
<
ModuleId
>>
=
new
Map
()
...
@@ -165,9 +169,12 @@ function getAffectedModuleEffects(
...
@@ -165,9 +169,12 @@ function getAffectedModuleEffects(
if
(
if
(
// The module is not in the cache. Since this is a "modified" update,
// The module is not in the cache. Since this is a "modified" update,
// it means that the module was never instantiated before.
// it means that the module was never instantiated before.
!
module
||
// The module accepted itself without invalidating globalThis.
!
module
||
// The module accepted itself without invalidating globalThis.
// TODO is that right?
// TODO is that right?
(
hotState
.
selfAccepted
&&
!
hotState
.
selfInvalidated
)
(
hotState
.
selfAccepted
&&
!
hotState
.
selfInvalidated
)
||
// Caller-defined accept boundary (e.g. App Router segment files).
isAutoAcceptModule
?.(
moduleId
)
)
{
)
{
continue
continue
}
}
...
@@ -269,10 +276,12 @@ function mergeDependencies(
...
@@ -269,10 +276,12 @@ function mergeDependencies(
*
*
* @param invalidated - The modules that have been invalidated
* @param invalidated - The modules that have been invalidated
* @param autoAcceptRootModules - If true, root modules auto-accept updates without explicit module.hot.accept()
* @param autoAcceptRootModules - If true, root modules auto-accept updates without explicit module.hot.accept()
* @param isAutoAcceptModule - Optional predicate for caller-defined accept boundaries
*/
*/
function
computedInvalidatedModules
(
function
computedInvalidatedModules
(
invalidated
:
Iterable
<
ModuleId
>
,
invalidated
:
Iterable
<
ModuleId
>
,
autoAcceptRootModules
:
boolean
autoAcceptRootModules
:
boolean
,
isAutoAcceptModule
?:
(
moduleId
:
ModuleId
)
=>
boolean
):
{
):
{
outdatedModules
:
Set
<
ModuleId
>
outdatedModules
:
Set
<
ModuleId
>
outdatedDependencies
:
Map
<
ModuleId
,
Set
<
ModuleId
>>
outdatedDependencies
:
Map
<
ModuleId
,
Set
<
ModuleId
>>
...
@@ -281,7 +290,11 @@ function computedInvalidatedModules(
...
@@ -281,7 +290,11 @@ function computedInvalidatedModules(
const
outdatedDependencies
=
new
Map
<
ModuleId
,
Set
<
ModuleId
>>
()
const
outdatedDependencies
=
new
Map
<
ModuleId
,
Set
<
ModuleId
>>
()
for
(
const
moduleId
of
invalidated
)
{
for
(
const
moduleId
of
invalidated
)
{
const
effect
=
getAffectedModuleEffects
(
moduleId
,
autoAcceptRootModules
)
const
effect
=
getAffectedModuleEffects
(
moduleId
,
autoAcceptRootModules
,
isAutoAcceptModule
)
switch
(
effect
.
type
)
{
switch
(
effect
.
type
)
{
case
'unaccepted'
:
case
'unaccepted'
:
...
@@ -422,11 +435,13 @@ function createModuleHot(
...
@@ -422,11 +435,13 @@ function createModuleHot(
*
*
* @param outdatedModules - The current set of outdated modules
* @param outdatedModules - The current set of outdated modules
* @param autoAcceptRootModules - If true, root modules auto-accept updates without explicit module.hot.accept()
* @param autoAcceptRootModules - If true, root modules auto-accept updates without explicit module.hot.accept()
* @param isAutoAcceptModule - Optional predicate for caller-defined accept boundaries
*/
*/
function applyInvalidatedModules(
function applyInvalidatedModules(
outdatedModules: Set<ModuleId>,
outdatedModules: Set<ModuleId>,
outdatedDependencies: Map<ModuleId, Set<ModuleId>>,
outdatedDependencies: Map<ModuleId, Set<ModuleId>>,
autoAcceptRootModules: boolean
autoAcceptRootModules: boolean,
isAutoAcceptModule?: (moduleId: ModuleId) => boolean
): {
): {
outdatedModules: Set<ModuleId>
outdatedModules: Set<ModuleId>
outdatedDependencies: Map<ModuleId, Set<ModuleId>>
outdatedDependencies: Map<ModuleId, Set<ModuleId>>
...
@@ -434,7 +449,8 @@ function applyInvalidatedModules(
...
@@ -434,7 +449,8 @@ function applyInvalidatedModules(
if (queuedInvalidatedModules.size > 0) {
if (queuedInvalidatedModules.size > 0) {
const result = computedInvalidatedModules(
const result = computedInvalidatedModules(
queuedInvalidatedModules,
queuedInvalidatedModules,
autoAcceptRootModules
autoAcceptRootModules,
isAutoAcceptModule
)
)
for (const moduleId of result.outdatedModules) {
for (const moduleId of result.outdatedModules) {
outdatedModules.add(moduleId)
outdatedModules.add(moduleId)
...
@@ -755,12 +771,14 @@ function computeChangedModules(
...
@@ -755,12 +771,14 @@ function computeChangedModules(
* @param modified - Map of modified modules
* @param modified - Map of modified modules
* @param evalModuleEntry - Function to compile module code
* @param evalModuleEntry - Function to compile module code
* @param autoAcceptRootModules - If true, root modules auto-accept updates without explicit module.hot.accept()
* @param autoAcceptRootModules - If true, root modules auto-accept updates without explicit module.hot.accept()
* @param isAutoAcceptModule - Optional predicate for caller-defined accept boundaries
*/
*/
function
computeOutdatedModules
(
function
computeOutdatedModules
(
added
:
Map
<
ModuleId
,
EcmascriptModuleEntry
|
undefined
>
,
added
:
Map
<
ModuleId
,
EcmascriptModuleEntry
|
undefined
>
,
modified
:
Map
<
ModuleId
,
EcmascriptModuleEntry
>
,
modified
:
Map
<
ModuleId
,
EcmascriptModuleEntry
>
,
evalModuleEntry
:
(
entry
:
EcmascriptModuleEntry
)
=>
HotModuleFactoryFunction
,
evalModuleEntry
:
(
entry
:
EcmascriptModuleEntry
)
=>
HotModuleFactoryFunction
,
autoAcceptRootModules
:
boolean
autoAcceptRootModules
:
boolean
,
isAutoAcceptModule
?:
(
moduleId
:
ModuleId
)
=>
boolean
):
{
):
{
outdatedModules
:
Set
<
ModuleId
>
outdatedModules
:
Set
<
ModuleId
>
outdatedDependencies
:
Map
<
ModuleId
,
Set
<
ModuleId
>>
outdatedDependencies
:
Map
<
ModuleId
,
Set
<
ModuleId
>>
...
@@ -778,7 +796,8 @@ function computeOutdatedModules(
...
@@ -778,7 +796,8 @@ function computeOutdatedModules(
// Walk dependency tree to find all modules affected by modifications
// Walk dependency tree to find all modules affected by modifications
const
{
outdatedModules
,
outdatedDependencies
}
=
computedInvalidatedModules
(
const
{
outdatedModules
,
outdatedDependencies
}
=
computedInvalidatedModules
(
modified
.
keys
(),
modified
.
keys
(),
autoAcceptRootModules
autoAcceptRootModules
,
isAutoAcceptModule
)
)
// Compile modified modules
// Compile modified modules
...
@@ -903,6 +922,7 @@ function applyPhase(
...
@@ -903,6 +922,7 @@ function applyPhase(
* invalidation, disposal, and application of new modules.
* invalidation, disposal, and application of new modules.
*
*
* @param autoAcceptRootModules - If true, root modules auto-accept updates without explicit module.hot.accept()
* @param autoAcceptRootModules - If true, root modules auto-accept updates without explicit module.hot.accept()
* @param isAutoAcceptModule - Optional predicate for caller-defined accept boundaries
*/
*/
function
applyInternal
(
function
applyInternal
(
outdatedModules
:
Set
<
ModuleId
>
,
outdatedModules
:
Set
<
ModuleId
>
,
...
@@ -917,12 +937,14 @@ function applyInternal(
...
@@ -917,12 +937,14 @@ function applyInternal(
sourceData
:
SourceData
sourceData
:
SourceData
)
=>
HotModule
,
)
=>
HotModule
,
applyModuleFactoryNameFn
:
(
factory
:
HotModuleFactoryFunction
)
=>
void
,
applyModuleFactoryNameFn
:
(
factory
:
HotModuleFactoryFunction
)
=>
void
,
autoAcceptRootModules
:
boolean
autoAcceptRootModules
:
boolean
,
isAutoAcceptModule
?:
(
moduleId
:
ModuleId
)
=>
boolean
)
{
)
{
;({
outdatedModules
,
outdatedDependencies
}
=
applyInvalidatedModules
(
;({
outdatedModules
,
outdatedDependencies
}
=
applyInvalidatedModules
(
outdatedModules
,
outdatedModules
,
outdatedDependencies
,
outdatedDependencies
,
autoAcceptRootModules
autoAcceptRootModules
,
isAutoAcceptModule
))
))
// Find self-accepted modules to re-instantiate
// Find self-accepted modules to re-instantiate
...
@@ -969,7 +991,8 @@ function applyInternal(
...
@@ -969,7 +991,8 @@ function applyInternal(
devModuleCache
,
devModuleCache
,
instantiateModuleFn
,
instantiateModuleFn
,
applyModuleFactoryNameFn
,
applyModuleFactoryNameFn
,
autoAcceptRootModules
autoAcceptRootModules
,
isAutoAcceptModule
)
)
}
}
}
}
...
@@ -981,6 +1004,10 @@ function applyInternal(
...
@@ -981,6 +1004,10 @@ function applyInternal(
* @param options.autoAcceptRootModules - If true, root modules auto-accept updates without explicit
* @param options.autoAcceptRootModules - If true, root modules auto-accept updates without explicit
* module.hot.accept(). Used for server-side HMR where pages
* module.hot.accept(). Used for server-side HMR where pages
* auto-accept at the top level.
* auto-accept at the top level.
* @param options.isAutoAcceptModule - Optional predicate. If provided and returns true for a module ID,
* that module acts as an HMR accept boundary regardless of its
* hot.accept() state. The update bubble stops there, and only that
* module (and its outdated dependencies) are re-instantiated.
*/
*/
function
applyEcmascriptMergedUpdateShared
(
options
:
{
function
applyEcmascriptMergedUpdateShared
(
options
:
{
added
:
Map
<
ModuleId
,
EcmascriptModuleEntry
|
undefined
>
added
:
Map
<
ModuleId
,
EcmascriptModuleEntry
|
undefined
>
...
@@ -996,6 +1023,7 @@ function applyEcmascriptMergedUpdateShared(options: {
...
@@ -996,6 +1023,7 @@ function applyEcmascriptMergedUpdateShared(options: {
moduleFactories
:
ModuleFactories
moduleFactories
:
ModuleFactories
devModuleCache
:
ModuleCache
<
HotModule
>
devModuleCache
:
ModuleCache
<
HotModule
>
autoAcceptRootModules
:
boolean
autoAcceptRootModules
:
boolean
isAutoAcceptModule
?:
(
moduleId
:
ModuleId
)
=>
boolean
})
{
})
{
const
{
const
{
added
,
added
,
...
@@ -1007,6 +1035,7 @@ function applyEcmascriptMergedUpdateShared(options: {
...
@@ -1007,6 +1035,7 @@ function applyEcmascriptMergedUpdateShared(options: {
moduleFactories
,
moduleFactories
,
devModuleCache
,
devModuleCache
,
autoAcceptRootModules
,
autoAcceptRootModules
,
isAutoAcceptModule
,
}
=
options
}
=
options
const
{
outdatedModules
,
outdatedDependencies
,
newModuleFactories
}
=
const
{
outdatedModules
,
outdatedDependencies
,
newModuleFactories
}
=
...
@@ -1014,7 +1043,8 @@ function applyEcmascriptMergedUpdateShared(options: {
...
@@ -1014,7 +1043,8 @@ function applyEcmascriptMergedUpdateShared(options: {
added
,
added
,
modified
,
modified
,
evalModuleEntry
,
evalModuleEntry
,
autoAcceptRootModules
autoAcceptRootModules
,
isAutoAcceptModule
)
)
applyInternal
(
applyInternal
(
...
@@ -1026,6 +1056,7 @@ function applyEcmascriptMergedUpdateShared(options: {
...
@@ -1026,6 +1056,7 @@ function applyEcmascriptMergedUpdateShared(options: {
devModuleCache
,
devModuleCache
,
instantiateModule
,
instantiateModule
,
applyModuleFactoryName
,
applyModuleFactoryName
,
autoAcceptRootModules
autoAcceptRootModules
,
isAutoAcceptModule
)
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment