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
2d987598
Unverified
Commit
2d987598
authored
Jul 10, 2022
by
Tim Neutkens
Committed by
GitHub
Jul 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle on-demand-entries and error overlay for server components (#38480)
parent
d920a171
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
696 additions
and
62 deletions
+696
-62
webpack-config.ts
packages/next/build/webpack-config.ts
+23
-8
next-app-loader.ts
packages/next/build/webpack/loaders/next-app-loader.ts
+6
-0
app-index.tsx
packages/next/client/app-index.tsx
+62
-7
app-next-dev.js
packages/next/client/app-next-dev.js
+14
-0
app-next.js
packages/next/client/app-next.js
+1
-35
app-router.client.tsx
packages/next/client/components/app-router.client.tsx
+3
-0
hot-reloader.client.tsx
packages/next/client/components/hot-reloader.client.tsx
+454
-0
app-render.tsx
packages/next/server/app-render.tsx
+7
-2
on-demand-entry-handler.ts
packages/next/server/dev/on-demand-entry-handler.ts
+116
-6
ReactDevOverlay.tsx
packages/react-dev-overlay/src/internal/ReactDevOverlay.tsx
+3
-1
ShadowPortal.tsx
...eact-dev-overlay/src/internal/components/ShadowPortal.tsx
+7
-3
No files found.
packages/next/build/webpack-config.ts
View file @
2d987598
...
@@ -571,14 +571,29 @@ export default async function getBaseWebpackConfig(
...
@@ -571,14 +571,29 @@ export default async function getBaseWebpackConfig(
.
replace
(
/
\\
/g
,
'/'
),
.
replace
(
/
\\
/g
,
'/'
),
...(
config
.
experimental
.
appDir
...(
config
.
experimental
.
appDir
?
{
?
{
[
CLIENT_STATIC_FILES_RUNTIME_MAIN_ROOT
]:
[
CLIENT_STATIC_FILES_RUNTIME_MAIN_ROOT
]:
dev
`./`
+
?
[
path
require
.
resolve
(
.
relative
(
`next/dist/compiled/@next/react-refresh-utils/dist/runtime`
dir
,
),
path
.
join
(
NEXT_PROJECT_ROOT_DIST_CLIENT
,
'app-next.js'
)
`./`
+
)
path
.
replace
(
/
\\
/g
,
'/'
),
.
relative
(
dir
,
path
.
join
(
NEXT_PROJECT_ROOT_DIST_CLIENT
,
'app-next-dev.js'
)
)
.
replace
(
/
\\
/g
,
'/'
),
]
:
`./`
+
path
.
relative
(
dir
,
path
.
join
(
NEXT_PROJECT_ROOT_DIST_CLIENT
,
'app-next.js'
)
)
.
replace
(
/
\\
/g
,
'/'
),
}
}
:
{}),
:
{}),
}
as
ClientEntries
)
}
as
ClientEntries
)
...
...
packages/next/build/webpack/loaders/next-app-loader.ts
View file @
2d987598
...
@@ -140,6 +140,12 @@ const nextAppLoader: webpack.LoaderDefinitionFunction<{
...
@@ -140,6 +140,12 @@ const nextAppLoader: webpack.LoaderDefinitionFunction<{
export const AppRouter = require('next/dist/client/components/app-router.client.js').default
export const AppRouter = require('next/dist/client/components/app-router.client.js').default
export const LayoutRouter = require('next/dist/client/components/layout-router.client.js').default
export const LayoutRouter = require('next/dist/client/components/layout-router.client.js').default
export const HotReloader =
${
// Disable HotReloader component in production
this
.
mode
===
'development'
?
`require('next/dist/client/components/hot-reloader.client.js').default`
:
'null'
}
export const hooksClientContext = require('next/dist/client/components/hooks-client-context.js')
export const hooksClientContext = require('next/dist/client/components/hooks-client-context.js')
export const __next_app_webpack_require__ = __webpack_require__
export const __next_app_webpack_require__ = __webpack_require__
...
...
packages/next/client/app-index.tsx
View file @
2d987598
...
@@ -8,6 +8,46 @@ import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-we
...
@@ -8,6 +8,46 @@ import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-we
/// <reference types="react-dom/experimental" />
/// <reference types="react-dom/experimental" />
// Override chunk URL mapping in the webpack runtime
// https://github.com/webpack/webpack/blob/2738eebc7880835d88c727d364ad37f3ec557593/lib/RuntimeGlobals.js#L204
declare
global
{
const
__webpack_require__
:
any
}
// eslint-disable-next-line no-undef
const
getChunkScriptFilename
=
__webpack_require__
.
u
const
chunkFilenameMap
:
any
=
{}
// eslint-disable-next-line no-undef
__webpack_require__
.
u
=
(
chunkId
:
any
)
=>
{
return
chunkFilenameMap
[
chunkId
]
||
getChunkScriptFilename
(
chunkId
)
}
// Ignore the module ID transform in client.
// eslint-disable-next-line no-undef
// @ts-expect-error TODO: fix type
self
.
__next_require__
=
__webpack_require__
// eslint-disable-next-line no-undef
// @ts-expect-error TODO: fix type
self
.
__next_chunk_load__
=
(
chunk
)
=>
{
if
(
chunk
.
endsWith
(
'.css'
))
{
const
link
=
document
.
createElement
(
'link'
)
link
.
rel
=
'stylesheet'
link
.
href
=
'/_next/'
+
chunk
document
.
head
.
appendChild
(
link
)
return
Promise
.
resolve
()
}
const
[
chunkId
,
chunkFileName
]
=
chunk
.
split
(
':'
)
chunkFilenameMap
[
chunkId
]
=
`static/chunks/
${
chunkFileName
}
.js`
// @ts-ignore
// eslint-disable-next-line no-undef
return
__webpack_chunk_load__
(
chunkId
)
}
export
const
version
=
process
.
env
.
__NEXT_VERSION
export
const
version
=
process
.
env
.
__NEXT_VERSION
const
appElement
:
HTMLElement
|
Document
|
null
=
document
const
appElement
:
HTMLElement
|
Document
|
null
=
document
...
@@ -119,7 +159,7 @@ function useInitialServerResponse(cacheKey: string) {
...
@@ -119,7 +159,7 @@ function useInitialServerResponse(cacheKey: string) {
return
newResponse
return
newResponse
}
}
const
ServerRoot
=
({
cacheKey
}:
{
cacheKey
:
string
})
=>
{
function
ServerRoot
({
cacheKey
}:
{
cacheKey
:
string
})
{
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
rscCache
.
delete
(
cacheKey
)
rscCache
.
delete
(
cacheKey
)
})
})
...
@@ -128,6 +168,19 @@ const ServerRoot = ({ cacheKey }: { cacheKey: string }) => {
...
@@ -128,6 +168,19 @@ const ServerRoot = ({ cacheKey }: { cacheKey: string }) => {
return
root
return
root
}
}
function
ErrorOverlay
({
children
,
}:
React
.
PropsWithChildren
<
{}
>
):
React
.
ReactElement
{
if
(
process
.
env
.
NODE_ENV
===
'production'
)
{
return
<>
{
children
}
</>
}
else
{
const
{
ReactDevOverlay
,
}
=
require
(
'next/dist/compiled/@next/react-dev-overlay/dist/client'
)
return
<
ReactDevOverlay
globalOverlay
>
{
children
}
</
ReactDevOverlay
>
}
}
function
Root
({
children
}:
React
.
PropsWithChildren
<
{}
>
):
React
.
ReactElement
{
function
Root
({
children
}:
React
.
PropsWithChildren
<
{}
>
):
React
.
ReactElement
{
if
(
process
.
env
.
__NEXT_TEST_MODE
)
{
if
(
process
.
env
.
__NEXT_TEST_MODE
)
{
// eslint-disable-next-line react-hooks/rules-of-hooks
// eslint-disable-next-line react-hooks/rules-of-hooks
...
@@ -143,17 +196,19 @@ function Root({ children }: React.PropsWithChildren<{}>): React.ReactElement {
...
@@ -143,17 +196,19 @@ function Root({ children }: React.PropsWithChildren<{}>): React.ReactElement {
return
children
as
React
.
ReactElement
return
children
as
React
.
ReactElement
}
}
const
RSCComponent
=
()
=>
{
function
RSCComponent
()
{
const
cacheKey
=
getCacheKey
()
const
cacheKey
=
getCacheKey
()
return
<
ServerRoot
cacheKey=
{
cacheKey
}
/>
return
<
ServerRoot
cacheKey=
{
cacheKey
}
/>
}
}
export
function
hydrate
()
{
export
function
hydrate
()
{
renderReactElement
(
appElement
!
,
()
=>
(
renderReactElement
(
appElement
!
,
()
=>
(
<
React
.
StrictMode
>
<
ErrorOverlay
>
<
Root
>
<
React
.
StrictMode
>
<
RSCComponent
/>
<
Root
>
</
Root
>
<
RSCComponent
/>
</
React
.
StrictMode
>
</
Root
>
</
React
.
StrictMode
>
</
ErrorOverlay
>
))
))
}
}
packages/next/client/app-next-dev.js
0 → 100644
View file @
2d987598
import
{
hydrate
,
version
}
from
'./app-index'
// TODO: implement FOUC guard
// TODO: hydration warning
window
.
next
=
{
version
,
appDir
:
true
,
}
hydrate
()
// TODO: build indicator
packages/next/client/app-next.js
View file @
2d987598
...
@@ -6,41 +6,7 @@ import 'next/dist/client/components/layout-router.client.js'
...
@@ -6,41 +6,7 @@ import 'next/dist/client/components/layout-router.client.js'
window
.
next
=
{
window
.
next
=
{
version
,
version
,
root
:
true
,
appDir
:
true
,
}
// Override chunk URL mapping in the webpack runtime
// https://github.com/webpack/webpack/blob/2738eebc7880835d88c727d364ad37f3ec557593/lib/RuntimeGlobals.js#L204
// eslint-disable-next-line no-undef
const
getChunkScriptFilename
=
__webpack_require__
.
u
const
chunkFilenameMap
=
{}
// eslint-disable-next-line no-undef
__webpack_require__
.
u
=
(
chunkId
)
=>
{
return
chunkFilenameMap
[
chunkId
]
||
getChunkScriptFilename
(
chunkId
)
}
// Ignore the module ID transform in client.
// eslint-disable-next-line no-undef
self
.
__next_require__
=
__webpack_require__
// eslint-disable-next-line no-undef
self
.
__next_chunk_load__
=
(
chunk
)
=>
{
if
(
chunk
.
endsWith
(
'.css'
))
{
const
link
=
document
.
createElement
(
'link'
)
link
.
rel
=
'stylesheet'
link
.
href
=
'/_next/'
+
chunk
document
.
head
.
appendChild
(
link
)
return
Promise
.
resolve
()
}
const
[
chunkId
,
chunkFileName
]
=
chunk
.
split
(
':'
)
chunkFilenameMap
[
chunkId
]
=
`static/chunks/
${
chunkFileName
}
.js`
// @ts-ignore
// eslint-disable-next-line no-undef
return
__webpack_chunk_load__
(
chunkId
)
}
}
hydrate
()
hydrate
()
packages/next/client/components/app-router.client.tsx
View file @
2d987598
...
@@ -50,10 +50,12 @@ export default function AppRouter({
...
@@ -50,10 +50,12 @@ export default function AppRouter({
initialTree
,
initialTree
,
initialCanonicalUrl
,
initialCanonicalUrl
,
children
,
children
,
hotReloader
,
}:
{
}:
{
initialTree
:
FlightRouterState
initialTree
:
FlightRouterState
initialCanonicalUrl
:
string
initialCanonicalUrl
:
string
children
:
React
.
ReactNode
children
:
React
.
ReactNode
hotReloader
?:
React
.
ReactNode
})
{
})
{
const
[{
tree
,
cache
,
pushRef
,
canonicalUrl
},
dispatch
]
=
React
.
useReducer
<
const
[{
tree
,
cache
,
pushRef
,
canonicalUrl
},
dispatch
]
=
React
.
useReducer
<
typeof
reducer
typeof
reducer
...
@@ -238,6 +240,7 @@ export default function AppRouter({
...
@@ -238,6 +240,7 @@ export default function AppRouter({
}
}
}
}
>
>
{
children
}
{
children
}
{
hotReloader
}
</
AppTreeContext
.
Provider
>
</
AppTreeContext
.
Provider
>
</
AppRouterContext
.
Provider
>
</
AppRouterContext
.
Provider
>
</
FullAppTreeContext
.
Provider
>
</
FullAppTreeContext
.
Provider
>
...
...
packages/next/client/components/hot-reloader.client.tsx
0 → 100644
View file @
2d987598
This diff is collapsed.
Click to expand it.
packages/next/server/app-render.tsx
View file @
2d987598
...
@@ -377,6 +377,9 @@ export async function renderToHTML(
...
@@ -377,6 +377,9 @@ export async function renderToHTML(
const
LayoutRouter
=
const
LayoutRouter
=
ComponentMod
.
LayoutRouter
as
typeof
import
(
'../client/components/layout-router.client'
).
default
ComponentMod
.
LayoutRouter
as
typeof
import
(
'../client/components/layout-router.client'
).
default
const
HotReloader
=
ComponentMod
.
HotReloader
as
|
typeof
import
(
'../client/components/hot-reloader.client'
).
default
|
null
const
headers
=
req
.
headers
const
headers
=
req
.
headers
// @ts-expect-error TODO: fix type of req
// @ts-expect-error TODO: fix type of req
...
@@ -746,7 +749,7 @@ export async function renderToHTML(
...
@@ -746,7 +749,7 @@ export async function renderToHTML(
const
search
=
stringifyQuery
(
query
)
const
search
=
stringifyQuery
(
query
)
// TODO: validate req.url as it gets passed to render.
// TODO: validate req.url as it gets passed to render.
const
initialCanonicalUrl
=
req
.
url
const
initialCanonicalUrl
=
req
.
url
!
// TODO: change tree to accommodate this
// TODO: change tree to accommodate this
// /blog/[...slug]/page.js -> /blog/hello-world/b/c/d -> ['children', 'blog', 'children', ['slug', 'hello-world/b/c/d']]
// /blog/[...slug]/page.js -> /blog/hello-world/b/c/d -> ['children', 'blog', 'children', ['slug', 'hello-world/b/c/d']]
...
@@ -760,7 +763,8 @@ export async function renderToHTML(
...
@@ -760,7 +763,8 @@ export async function renderToHTML(
firstItem
:
true
,
firstItem
:
true
,
})
})
const
AppRouter
=
ComponentMod
.
AppRouter
const
AppRouter
=
ComponentMod
.
AppRouter
as
typeof
import
(
'../client/components/app-router.client'
).
default
const
{
const
{
QueryContext
,
QueryContext
,
PathnameContext
,
PathnameContext
,
...
@@ -774,6 +778,7 @@ export async function renderToHTML(
...
@@ -774,6 +778,7 @@ export async function renderToHTML(
<
PathnameContext
.
Provider
value=
{
pathname
}
>
<
PathnameContext
.
Provider
value=
{
pathname
}
>
{
/* <ParamsContext.Provider value={pathParams}> */
}
{
/* <ParamsContext.Provider value={pathParams}> */
}
<
AppRouter
<
AppRouter
hotReloader=
{
HotReloader
&&
<
HotReloader
assetPrefix=
""
/>
}
initialCanonicalUrl=
{
initialCanonicalUrl
}
initialCanonicalUrl=
{
initialCanonicalUrl
}
initialTree=
{
initialTree
}
initialTree=
{
initialTree
}
>
>
...
...
packages/next/server/dev/on-demand-entry-handler.ts
View file @
2d987598
...
@@ -15,6 +15,56 @@ import { serverComponentRegex } from '../../build/webpack/loaders/utils'
...
@@ -15,6 +15,56 @@ import { serverComponentRegex } from '../../build/webpack/loaders/utils'
import
{
getPageStaticInfo
}
from
'../../build/analysis/get-page-static-info'
import
{
getPageStaticInfo
}
from
'../../build/analysis/get-page-static-info'
import
{
isMiddlewareFile
,
isMiddlewareFilename
}
from
'../../build/utils'
import
{
isMiddlewareFile
,
isMiddlewareFilename
}
from
'../../build/utils'
import
{
PageNotFoundError
}
from
'../../shared/lib/utils'
import
{
PageNotFoundError
}
from
'../../shared/lib/utils'
import
{
FlightRouterState
}
from
'../app-render'
function
treePathToEntrypoint
(
segmentPath
:
string
[],
parentPath
?:
string
):
string
{
const
[
parallelRouteKey
,
segment
]
=
segmentPath
const
path
=
(
parentPath
?
parentPath
+
'/'
:
''
)
+
(
parallelRouteKey
!==
'children'
?
parallelRouteKey
+
'/'
:
''
)
+
(
segment
===
''
?
'page'
:
segment
)
// Last segment
if
(
segmentPath
.
length
===
2
)
{
return
path
}
const
childSegmentPath
=
segmentPath
.
slice
(
2
)
return
treePathToEntrypoint
(
childSegmentPath
,
path
)
}
function
getEntrypointsFromTree
(
tree
:
FlightRouterState
,
isFirst
:
boolean
,
parentPath
:
string
[]
=
[]
)
{
const
[
segment
,
parallelRoutes
]
=
tree
const
currentSegment
=
Array
.
isArray
(
segment
)
?
segment
[
0
]
:
segment
const
currentPath
=
[...
parentPath
,
currentSegment
]
if
(
!
isFirst
&&
currentSegment
===
''
)
{
// TODO get rid of '' at the start of tree
return
[
treePathToEntrypoint
(
currentPath
.
slice
(
1
))]
}
return
Object
.
keys
(
parallelRoutes
).
reduce
(
(
paths
:
string
[],
key
:
string
):
string
[]
=>
{
const
childTree
=
parallelRoutes
[
key
]
const
childPages
=
getEntrypointsFromTree
(
childTree
,
false
,
[
...
currentPath
,
key
,
])
return
[...
paths
,
...
childPages
]
},
[]
)
}
export
const
ADDED
=
Symbol
(
'added'
)
export
const
ADDED
=
Symbol
(
'added'
)
export
const
BUILDING
=
Symbol
(
'building'
)
export
const
BUILDING
=
Symbol
(
'building'
)
...
@@ -78,6 +128,7 @@ export function onDemandEntryHandler({
...
@@ -78,6 +128,7 @@ export function onDemandEntryHandler({
invalidator
=
new
Invalidator
(
multiCompiler
)
invalidator
=
new
Invalidator
(
multiCompiler
)
const
doneCallbacks
:
EventEmitter
|
null
=
new
EventEmitter
()
const
doneCallbacks
:
EventEmitter
|
null
=
new
EventEmitter
()
const
lastClientAccessPages
=
[
''
]
const
lastClientAccessPages
=
[
''
]
const
lastServerAccessPagesForAppDir
=
[
''
]
const
startBuilding
=
(
_compilation
:
webpack
.
Compilation
)
=>
{
const
startBuilding
=
(
_compilation
:
webpack
.
Compilation
)
=>
{
invalidator
.
startBuilding
()
invalidator
.
startBuilding
()
...
@@ -153,9 +204,48 @@ export function onDemandEntryHandler({
...
@@ -153,9 +204,48 @@ export function onDemandEntryHandler({
const
pingIntervalTime
=
Math
.
max
(
1000
,
Math
.
min
(
5000
,
maxInactiveAge
))
const
pingIntervalTime
=
Math
.
max
(
1000
,
Math
.
min
(
5000
,
maxInactiveAge
))
setInterval
(
function
()
{
setInterval
(
function
()
{
disposeInactiveEntries
(
lastClientAccessPages
,
maxInactiveAge
)
disposeInactiveEntries
(
lastClientAccessPages
,
lastServerAccessPagesForAppDir
,
maxInactiveAge
)
},
pingIntervalTime
+
1000
).
unref
()
},
pingIntervalTime
+
1000
).
unref
()
function
handleAppDirPing
(
tree
:
FlightRouterState
):
{
success
:
true
}
|
{
invalid
:
true
}
{
const
pages
=
getEntrypointsFromTree
(
tree
,
true
)
for
(
const
page
of
pages
)
{
const
pageKey
=
`server/
${
page
}
`
const
entryInfo
=
entries
[
pageKey
]
// If there's no entry, it may have been invalidated and needs to be re-built.
if
(
!
entryInfo
)
{
// if (page !== lastEntry) client pings, but there's no entry for page
return
{
invalid
:
true
}
}
// We don't need to maintain active state of anything other than BUILT entries
if
(
entryInfo
.
status
!==
BUILT
)
continue
// If there's an entryInfo
if
(
!
lastServerAccessPagesForAppDir
.
includes
(
pageKey
))
{
lastServerAccessPagesForAppDir
.
unshift
(
pageKey
)
// Maintain the buffer max length
// TODO: verify that the current pageKey is not at the end of the array as multiple entrypoints can exist
if
(
lastServerAccessPagesForAppDir
.
length
>
pagesBufferLength
)
{
lastServerAccessPagesForAppDir
.
pop
()
}
}
entryInfo
.
lastActiveTime
=
Date
.
now
()
entryInfo
.
dispose
=
false
}
return
{
success
:
true
}
}
function
handlePing
(
pg
:
string
)
{
function
handlePing
(
pg
:
string
)
{
const
page
=
normalizePathSep
(
pg
)
const
page
=
normalizePathSep
(
pg
)
const
pageKey
=
`client
${
page
}
`
const
pageKey
=
`client
${
page
}
`
...
@@ -272,11 +362,13 @@ export function onDemandEntryHandler({
...
@@ -272,11 +362,13 @@ export function onDemandEntryHandler({
)
)
if
(
parsedData
.
event
===
'ping'
)
{
if
(
parsedData
.
event
===
'ping'
)
{
const
result
=
handlePing
(
parsedData
.
page
)
const
result
=
parsedData
.
appDirRoute
?
handleAppDirPing
(
parsedData
.
tree
)
:
handlePing
(
parsedData
.
page
)
client
.
send
(
client
.
send
(
JSON
.
stringify
({
JSON
.
stringify
({
...
result
,
...
result
,
event
:
'pong'
,
[
parsedData
.
appDirRoute
?
'action'
:
'event'
]
:
'pong'
,
})
})
)
)
}
}
...
@@ -288,10 +380,17 @@ export function onDemandEntryHandler({
...
@@ -288,10 +380,17 @@ export function onDemandEntryHandler({
function
disposeInactiveEntries
(
function
disposeInactiveEntries
(
lastClientAccessPages
:
string
[],
lastClientAccessPages
:
string
[],
lastServerAccessPagesForAppDir
:
string
[],
maxInactiveAge
:
number
maxInactiveAge
:
number
)
{
)
{
Object
.
keys
(
entries
).
forEach
((
page
)
=>
{
Object
.
keys
(
entries
).
forEach
((
page
)
=>
{
const
{
lastActiveTime
,
status
,
dispose
}
=
entries
[
page
]
const
{
lastActiveTime
,
status
,
dispose
,
bundlePath
}
=
entries
[
page
]
const
isClientComponentsEntry
=
bundlePath
.
startsWith
(
'app/'
)
&&
page
.
startsWith
(
'client/'
)
// Disposing client component entry is handled when disposing server component entry
if
(
isClientComponentsEntry
)
return
// Skip pages already scheduled for disposing
// Skip pages already scheduled for disposing
if
(
dispose
)
return
if
(
dispose
)
return
...
@@ -303,15 +402,26 @@ function disposeInactiveEntries(
...
@@ -303,15 +402,26 @@ function disposeInactiveEntries(
// We should not build the last accessed page even we didn't get any pings
// We should not build the last accessed page even we didn't get any pings
// Sometimes, it's possible our XHR ping to wait before completing other requests.
// Sometimes, it's possible our XHR ping to wait before completing other requests.
// In that case, we should not dispose the current viewing page
// In that case, we should not dispose the current viewing page
if
(
lastClientAccessPages
.
includes
(
page
))
return
if
(
lastClientAccessPages
.
includes
(
page
)
||
lastServerAccessPagesForAppDir
.
includes
(
page
)
)
return
if
(
lastActiveTime
&&
Date
.
now
()
-
lastActiveTime
>
maxInactiveAge
)
{
if
(
lastActiveTime
&&
Date
.
now
()
-
lastActiveTime
>
maxInactiveAge
)
{
const
isServerComponentsEntry
=
bundlePath
.
startsWith
(
'app/'
)
&&
page
.
startsWith
(
'server/'
)
// Dispose client component entrypoint when server component entrypoint is disposed.
if
(
isServerComponentsEntry
)
{
entries
[
page
.
replace
(
'server/'
,
'client/'
)].
dispose
=
true
}
entries
[
page
].
dispose
=
true
entries
[
page
].
dispose
=
true
}
}
})
})
}
}
// Make sure only one invalidation happens at a time
// Make sure only one invalidation happens at a time
∫
// Otherwise, webpack hash gets changed and it'll force the client to reload.
// Otherwise, webpack hash gets changed and it'll force the client to reload.
class
Invalidator
{
class
Invalidator
{
private
multiCompiler
:
webpack
.
MultiCompiler
private
multiCompiler
:
webpack
.
MultiCompiler
...
...
packages/react-dev-overlay/src/internal/ReactDevOverlay.tsx
View file @
2d987598
...
@@ -47,9 +47,11 @@ type ErrorType = 'runtime' | 'build'
...
@@ -47,9 +47,11 @@ type ErrorType = 'runtime' | 'build'
const
ReactDevOverlay
:
React
.
FunctionComponent
=
function
ReactDevOverlay
({
const
ReactDevOverlay
:
React
.
FunctionComponent
=
function
ReactDevOverlay
({
children
,
children
,
preventDisplay
,
preventDisplay
,
globalOverlay
,
}:
{
}:
{
children
?:
React
.
ReactNode
children
?:
React
.
ReactNode
preventDisplay
?:
ErrorType
[]
preventDisplay
?:
ErrorType
[]
globalOverlay
?:
boolean
})
{
})
{
const
[
state
,
dispatch
]
=
React
.
useReducer
<
const
[
state
,
dispatch
]
=
React
.
useReducer
<
React
.
Reducer
<
OverlayState
,
Bus
.
BusEvent
>
React
.
Reducer
<
OverlayState
,
Bus
.
BusEvent
>
...
@@ -84,7 +86,7 @@ const ReactDevOverlay: React.FunctionComponent = function ReactDevOverlay({
...
@@ -84,7 +86,7 @@ const ReactDevOverlay: React.FunctionComponent = function ReactDevOverlay({
{
children
??
null
}
{
children
??
null
}
</
ErrorBoundary
>
</
ErrorBoundary
>
{
isMounted
?
(
{
isMounted
?
(
<
ShadowPortal
>
<
ShadowPortal
globalOverlay=
{
globalOverlay
}
>
<
CssReset
/>
<
CssReset
/>
<
Base
/>
<
Base
/>
<
ComponentStyles
/>
<
ComponentStyles
/>
...
...
packages/react-dev-overlay/src/internal/components/ShadowPortal.tsx
View file @
2d987598
...
@@ -3,10 +3,12 @@ import { createPortal } from 'react-dom'
...
@@ -3,10 +3,12 @@ import { createPortal } from 'react-dom'
export
type
ShadowPortalProps
=
{
export
type
ShadowPortalProps
=
{
children
:
React
.
ReactNode
children
:
React
.
ReactNode
globalOverlay
?:
boolean
}
}
export
const
ShadowPortal
:
React
.
FC
<
ShadowPortalProps
>
=
function
Portal
({
export
const
ShadowPortal
:
React
.
FC
<
ShadowPortalProps
>
=
function
Portal
({
children
,
children
,
globalOverlay
,
})
{
})
{
let
mountNode
=
React
.
useRef
<
HTMLDivElement
|
null
>
(
null
)
let
mountNode
=
React
.
useRef
<
HTMLDivElement
|
null
>
(
null
)
let
portalNode
=
React
.
useRef
<
HTMLElement
|
null
>
(
null
)
let
portalNode
=
React
.
useRef
<
HTMLElement
|
null
>
(
null
)
...
@@ -14,7 +16,9 @@ export const ShadowPortal: React.FC<ShadowPortalProps> = function Portal({
...
@@ -14,7 +16,9 @@ export const ShadowPortal: React.FC<ShadowPortalProps> = function Portal({
let
[,
forceUpdate
]
=
React
.
useState
<
{}
|
undefined
>
()
let
[,
forceUpdate
]
=
React
.
useState
<
{}
|
undefined
>
()
React
.
useLayoutEffect
(()
=>
{
React
.
useLayoutEffect
(()
=>
{
const
ownerDocument
=
mountNode
.
current
!
.
ownerDocument
!
const
ownerDocument
=
globalOverlay
?
document
:
mountNode
.
current
!
.
ownerDocument
!
portalNode
.
current
=
ownerDocument
.
createElement
(
'nextjs-portal'
)
portalNode
.
current
=
ownerDocument
.
createElement
(
'nextjs-portal'
)
shadowNode
.
current
=
portalNode
.
current
.
attachShadow
({
mode
:
'open'
})
shadowNode
.
current
=
portalNode
.
current
.
attachShadow
({
mode
:
'open'
})
ownerDocument
.
body
.
appendChild
(
portalNode
.
current
)
ownerDocument
.
body
.
appendChild
(
portalNode
.
current
)
...
@@ -24,11 +28,11 @@ export const ShadowPortal: React.FC<ShadowPortalProps> = function Portal({
...
@@ -24,11 +28,11 @@ export const ShadowPortal: React.FC<ShadowPortalProps> = function Portal({
portalNode
.
current
.
ownerDocument
.
body
.
removeChild
(
portalNode
.
current
)
portalNode
.
current
.
ownerDocument
.
body
.
removeChild
(
portalNode
.
current
)
}
}
}
}
},
[])
},
[
globalOverlay
])
return
shadowNode
.
current
?
(
return
shadowNode
.
current
?
(
createPortal
(
children
,
shadowNode
.
current
as
any
)
createPortal
(
children
,
shadowNode
.
current
as
any
)
)
:
(
)
:
globalOverlay
?
null
:
(
<
span
ref=
{
mountNode
}
/>
<
span
ref=
{
mountNode
}
/>
)
)
}
}
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