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
24f450e8
Unverified
Commit
24f450e8
authored
Mar 17, 2022
by
Shu Ding
Committed by
GitHub
Mar 17, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Make concurrent features independent from the global runtime option" (#35405)
Reverts vercel/next.js#35245
parent
52e34ced
Show whitespace changes
Inline
Side-by-side
Showing
40 changed files
with
60 additions
and
468 deletions
+60
-468
entries.ts
packages/next/build/entries.ts
+3
-0
index.ts
packages/next/build/index.ts
+10
-25
webpack-config.ts
packages/next/build/webpack-config.ts
+6
-7
index.ts
packages/next/export/index.ts
+0
-1
worker.ts
packages/next/export/worker.ts
+2
-9
_document.tsx
packages/next/pages/_document.tsx
+3
-1
hot-reloader.ts
packages/next/server/dev/hot-reloader.ts
+4
-9
load-components.ts
packages/next/server/load-components.ts
+5
-13
next-server.ts
packages/next/server/next-server.ts
+1
-1
render.tsx
packages/next/server/render.tsx
+7
-8
html-context.ts
packages/next/shared/lib/html-context.ts
+0
-1
index.test.js
test/integration/react-18-invalid-config/index.test.js
+13
-0
no-preload.js
test/integration/react-18/app/pages/suspense/no-preload.js
+1
-2
basics.js
test/integration/react-18/test/basics.js
+1
-1
blocking.js
test/integration/react-18/test/blocking.js
+3
-4
render.js
...t-streaming-and-server-components/app/pages/err/render.js
+0
-4
suspense.js
...streaming-and-server-components/app/pages/err/suspense.js
+0
-4
image.server.js
...-and-server-components/app/pages/next-api/image.server.js
+0
-4
link.server.js
...g-and-server-components/app/pages/next-api/link.server.js
+0
-4
partial-hydration.server.js
...d-server-components/app/pages/partial-hydration.server.js
+0
-4
[dynamic].server.js
...nd-server-components/app/pages/routes/[dynamic].server.js
+0
-4
streaming-rsc.server.js
...g-and-server-components/app/pages/streaming-rsc.server.js
+0
-4
streaming.js
...ct-streaming-and-server-components/app/pages/streaming.js
+0
-4
next.config.js
...g-and-server-components/switchable-runtime/next.config.js
+0
-9
package.json
...ing-and-server-components/switchable-runtime/package.json
+0
-9
pages-manifest.json
...-server-components/switchable-runtime/pages-manifest.json
+0
-9
edge-rsc.server.js
...er-components/switchable-runtime/pages/edge-rsc.server.js
+0
-18
edge.js
...ng-and-server-components/switchable-runtime/pages/edge.js
+0
-18
node-rsc-ssg.server.js
...omponents/switchable-runtime/pages/node-rsc-ssg.server.js
+0
-26
node-rsc-ssr.server.js
...omponents/switchable-runtime/pages/node-rsc-ssr.server.js
+0
-26
node-rsc.server.js
...er-components/switchable-runtime/pages/node-rsc.server.js
+0
-18
node-ssg.js
...nd-server-components/switchable-runtime/pages/node-ssg.js
+0
-26
node-ssr.js
...nd-server-components/switchable-runtime/pages/node-ssr.js
+0
-26
node.js
...ng-and-server-components/switchable-runtime/pages/node.js
+0
-18
static.js
...-and-server-components/switchable-runtime/pages/static.js
+0
-14
runtime.js
...and-server-components/switchable-runtime/utils/runtime.js
+0
-3
time.js
...ng-and-server-components/switchable-runtime/utils/time.js
+0
-3
switchable-runtime.test.js
...ing-and-server-components/test/switchable-runtime.test.js
+0
-127
next.config.js
...erver-components/unsupported-native-module/next.config.js
+1
-0
index.js
...erver-components/unsupported-native-module/pages/index.js
+0
-4
No files found.
packages/next/build/entries.ts
View file @
24f450e8
...
@@ -187,6 +187,9 @@ export async function getPageRuntime(
...
@@ -187,6 +187,9 @@ export async function getPageRuntime(
if
(
!
pageRuntime
)
{
if
(
!
pageRuntime
)
{
if
(
isRuntimeRequired
)
{
if
(
isRuntimeRequired
)
{
pageRuntime
=
globalRuntimeFallback
pageRuntime
=
globalRuntimeFallback
}
else
{
// @TODO: Remove this branch to fully implement the RFC.
pageRuntime
=
globalRuntimeFallback
}
}
}
}
...
...
packages/next/build/index.ts
View file @
24f450e8
...
@@ -76,11 +76,7 @@ import {
...
@@ -76,11 +76,7 @@ import {
}
from
'../telemetry/events'
}
from
'../telemetry/events'
import
{
Telemetry
}
from
'../telemetry/storage'
import
{
Telemetry
}
from
'../telemetry/storage'
import
{
CompilerResult
,
runCompiler
}
from
'./compiler'
import
{
CompilerResult
,
runCompiler
}
from
'./compiler'
import
{
import
{
createEntrypoints
,
createPagesMapping
}
from
'./entries'
createEntrypoints
,
createPagesMapping
,
getPageRuntime
,
}
from
'./entries'
import
{
generateBuildId
}
from
'./generate-build-id'
import
{
generateBuildId
}
from
'./generate-build-id'
import
{
isWriteable
}
from
'./is-writeable'
import
{
isWriteable
}
from
'./is-writeable'
import
*
as
Log
from
'./output/log'
import
*
as
Log
from
'./output/log'
...
@@ -157,10 +153,11 @@ export default async function build(
...
@@ -157,10 +153,11 @@ export default async function build(
setGlobal
(
'phase'
,
PHASE_PRODUCTION_BUILD
)
setGlobal
(
'phase'
,
PHASE_PRODUCTION_BUILD
)
setGlobal
(
'distDir'
,
distDir
)
setGlobal
(
'distDir'
,
distDir
)
// We enable concurrent features (Fizz-related rendering architecture) when
// Currently, when the runtime option is set (either `nodejs` or `edge`),
// using React 18 or experimental.
// we enable concurrent features (Fizz-related rendering architecture).
const
runtime
=
config
.
experimental
.
runtime
const
hasReactRoot
=
shouldUseReactRoot
()
const
hasReactRoot
=
shouldUseReactRoot
()
const
hasConcurrentFeatures
=
hasReactRoot
const
hasConcurrentFeatures
=
!!
runtime
const
hasServerComponents
=
const
hasServerComponents
=
hasReactRoot
&&
!!
config
.
experimental
.
serverComponents
hasReactRoot
&&
!!
config
.
experimental
.
serverComponents
...
@@ -625,7 +622,6 @@ export default async function build(
...
@@ -625,7 +622,6 @@ export default async function build(
entrypoints
:
entrypoints
.
client
,
entrypoints
:
entrypoints
.
client
,
rewrites
,
rewrites
,
runWebpackSpan
,
runWebpackSpan
,
hasReactRoot
,
}),
}),
getBaseWebpackConfig
(
dir
,
{
getBaseWebpackConfig
(
dir
,
{
buildId
,
buildId
,
...
@@ -637,7 +633,6 @@ export default async function build(
...
@@ -637,7 +633,6 @@ export default async function build(
entrypoints
:
entrypoints
.
server
,
entrypoints
:
entrypoints
.
server
,
rewrites
,
rewrites
,
runWebpackSpan
,
runWebpackSpan
,
hasReactRoot
,
}),
}),
hasReactRoot
hasReactRoot
?
getBaseWebpackConfig
(
dir
,
{
?
getBaseWebpackConfig
(
dir
,
{
...
@@ -651,7 +646,6 @@ export default async function build(
...
@@ -651,7 +646,6 @@ export default async function build(
entrypoints
:
entrypoints
.
edgeServer
,
entrypoints
:
entrypoints
.
edgeServer
,
rewrites
,
rewrites
,
runWebpackSpan
,
runWebpackSpan
,
hasReactRoot
,
})
})
:
null
,
:
null
,
])
])
...
@@ -960,22 +954,10 @@ export default async function build(
...
@@ -960,22 +954,10 @@ export default async function build(
let
ssgPageRoutes
:
string
[]
|
null
=
null
let
ssgPageRoutes
:
string
[]
|
null
=
null
let
isMiddlewareRoute
=
!!
page
.
match
(
MIDDLEWARE_ROUTE
)
let
isMiddlewareRoute
=
!!
page
.
match
(
MIDDLEWARE_ROUTE
)
const
pagePath
=
pagePaths
.
find
((
_path
)
=>
_path
.
startsWith
(
actualPage
+
'.'
)
)
const
pageRuntime
=
hasConcurrentFeatures
&&
pagePath
?
await
getPageRuntime
(
join
(
pagesDir
,
pagePath
),
config
.
experimental
.
runtime
)
:
null
if
(
if
(
!
isMiddlewareRoute
&&
!
isMiddlewareRoute
&&
!
isReservedPage
(
page
)
&&
!
isReservedPage
(
page
)
&&
// We currently don't support staic optimization in the Edge runtime.
!
hasConcurrentFeatures
pageRuntime
!==
'edge'
)
{
)
{
try
{
try
{
let
isPageStaticSpan
=
let
isPageStaticSpan
=
...
@@ -1501,7 +1483,10 @@ export default async function build(
...
@@ -1501,7 +1483,10 @@ export default async function build(
const
combinedPages
=
[...
staticPages
,
...
ssgPages
]
const
combinedPages
=
[...
staticPages
,
...
ssgPages
]
if
(
combinedPages
.
length
>
0
||
useStatic404
||
useDefaultStatic500
)
{
if
(
!
hasConcurrentFeatures
&&
(
combinedPages
.
length
>
0
||
useStatic404
||
useDefaultStatic500
)
)
{
const
staticGenerationSpan
=
nextBuildSpan
.
traceChild
(
'static-generation'
)
const
staticGenerationSpan
=
nextBuildSpan
.
traceChild
(
'static-generation'
)
await
staticGenerationSpan
.
traceAsyncFn
(
async
()
=>
{
await
staticGenerationSpan
.
traceAsyncFn
(
async
()
=>
{
detectConflictingPaths
(
detectConflictingPaths
(
...
...
packages/next/build/webpack-config.ts
View file @
24f450e8
...
@@ -48,6 +48,7 @@ import type { Span } from '../trace'
...
@@ -48,6 +48,7 @@ import type { Span } from '../trace'
import
{
getRawPageExtensions
}
from
'./utils'
import
{
getRawPageExtensions
}
from
'./utils'
import
browserslist
from
'next/dist/compiled/browserslist'
import
browserslist
from
'next/dist/compiled/browserslist'
import
loadJsConfig
from
'./load-jsconfig'
import
loadJsConfig
from
'./load-jsconfig'
import
{
shouldUseReactRoot
}
from
'../server/config'
import
{
getMiddlewareSourceMapPlugins
}
from
'./webpack/plugins/middleware-source-maps-plugin'
import
{
getMiddlewareSourceMapPlugins
}
from
'./webpack/plugins/middleware-source-maps-plugin'
const
watchOptions
=
Object
.
freeze
({
const
watchOptions
=
Object
.
freeze
({
...
@@ -309,7 +310,6 @@ export default async function getBaseWebpackConfig(
...
@@ -309,7 +310,6 @@ export default async function getBaseWebpackConfig(
rewrites
,
rewrites
,
isDevFallback
=
false
,
isDevFallback
=
false
,
runWebpackSpan
,
runWebpackSpan
,
hasReactRoot
,
}:
{
}:
{
buildId
:
string
buildId
:
string
config
:
NextConfigComplete
config
:
NextConfigComplete
...
@@ -323,7 +323,6 @@ export default async function getBaseWebpackConfig(
...
@@ -323,7 +323,6 @@ export default async function getBaseWebpackConfig(
rewrites
:
CustomRoutes
[
'rewrites'
]
rewrites
:
CustomRoutes
[
'rewrites'
]
isDevFallback
?:
boolean
isDevFallback
?:
boolean
runWebpackSpan
:
Span
runWebpackSpan
:
Span
hasReactRoot
:
boolean
}
}
):
Promise
<
webpack
.
Configuration
>
{
):
Promise
<
webpack
.
Configuration
>
{
const
{
useTypeScript
,
jsConfig
,
resolvedBaseUrl
}
=
await
loadJsConfig
(
const
{
useTypeScript
,
jsConfig
,
resolvedBaseUrl
}
=
await
loadJsConfig
(
...
@@ -336,10 +335,10 @@ export default async function getBaseWebpackConfig(
...
@@ -336,10 +335,10 @@ export default async function getBaseWebpackConfig(
rewrites
.
afterFiles
.
length
>
0
||
rewrites
.
afterFiles
.
length
>
0
||
rewrites
.
fallback
.
length
>
0
rewrites
.
fallback
.
length
>
0
const
hasReactRefresh
:
boolean
=
dev
&&
!
isServer
const
hasReactRefresh
:
boolean
=
dev
&&
!
isServer
const
hasReactRoot
=
shouldUseReactRoot
()
const
runtime
=
config
.
experimental
.
runtime
const
runtime
=
config
.
experimental
.
runtime
// Make sure
`reactRoot` is enabled when React 18 or experimental is detected.
// Make sure
reactRoot is enabled when react 18 is detected
if
(
hasReactRoot
)
{
if
(
hasReactRoot
)
{
config
.
experimental
.
reactRoot
=
true
config
.
experimental
.
reactRoot
=
true
}
}
...
@@ -354,14 +353,14 @@ export default async function getBaseWebpackConfig(
...
@@ -354,14 +353,14 @@ export default async function getBaseWebpackConfig(
'`experimental.runtime` requires `experimental.reactRoot` to be enabled along with React 18.'
'`experimental.runtime` requires `experimental.reactRoot` to be enabled along with React 18.'
)
)
}
}
if
(
config
.
experimental
.
serverComponents
&&
!
hasReactRoot
)
{
if
(
config
.
experimental
.
serverComponents
&&
!
runtime
)
{
throw
new
Error
(
throw
new
Error
(
'`experimental.
serverComponents` requires React 18 to be installed
.'
'`experimental.
runtime` is required to be set along with `experimental.serverComponents`
.'
)
)
}
}
const
targetWeb
=
isEdgeRuntime
||
!
isServer
const
targetWeb
=
isEdgeRuntime
||
!
isServer
const
hasConcurrentFeatures
=
hasReactRoot
const
hasConcurrentFeatures
=
!!
runtime
&&
hasReactRoot
const
hasServerComponents
=
const
hasServerComponents
=
hasConcurrentFeatures
&&
!!
config
.
experimental
.
serverComponents
hasConcurrentFeatures
&&
!!
config
.
experimental
.
serverComponents
const
disableOptimizedLoading
=
hasConcurrentFeatures
const
disableOptimizedLoading
=
hasConcurrentFeatures
...
...
packages/next/export/index.ts
View file @
24f450e8
...
@@ -588,7 +588,6 @@ export default async function exportApp(
...
@@ -588,7 +588,6 @@ export default async function exportApp(
nextConfig
.
experimental
.
disableOptimizedLoading
,
nextConfig
.
experimental
.
disableOptimizedLoading
,
parentSpanId
:
pageExportSpan
.
id
,
parentSpanId
:
pageExportSpan
.
id
,
httpAgentOptions
:
nextConfig
.
httpAgentOptions
,
httpAgentOptions
:
nextConfig
.
httpAgentOptions
,
serverComponents
:
nextConfig
.
experimental
.
serverComponents
,
})
})
for
(
const
validation
of
result
.
ampValidations
||
[])
{
for
(
const
validation
of
result
.
ampValidations
||
[])
{
...
...
packages/next/export/worker.ts
View file @
24f450e8
...
@@ -59,7 +59,6 @@ interface ExportPageInput {
...
@@ -59,7 +59,6 @@ interface ExportPageInput {
disableOptimizedLoading
:
any
disableOptimizedLoading
:
any
parentSpanId
:
any
parentSpanId
:
any
httpAgentOptions
:
NextConfigComplete
[
'httpAgentOptions'
]
httpAgentOptions
:
NextConfigComplete
[
'httpAgentOptions'
]
serverComponents
?:
boolean
}
}
interface
ExportPageResults
{
interface
ExportPageResults
{
...
@@ -107,7 +106,6 @@ export default async function exportPage({
...
@@ -107,7 +106,6 @@ export default async function exportPage({
optimizeCss
,
optimizeCss
,
disableOptimizedLoading
,
disableOptimizedLoading
,
httpAgentOptions
,
httpAgentOptions
,
serverComponents
,
}:
ExportPageInput
):
Promise
<
ExportPageResults
>
{
}:
ExportPageInput
):
Promise
<
ExportPageResults
>
{
setHttpAgentOptions
(
httpAgentOptions
)
setHttpAgentOptions
(
httpAgentOptions
)
const
exportPageSpan
=
trace
(
'export-page-worker'
,
parentSpanId
)
const
exportPageSpan
=
trace
(
'export-page-worker'
,
parentSpanId
)
...
@@ -262,7 +260,7 @@ export default async function exportPage({
...
@@ -262,7 +260,7 @@ export default async function exportPage({
getServerSideProps
,
getServerSideProps
,
getStaticProps
,
getStaticProps
,
pageConfig
,
pageConfig
,
}
=
await
loadComponents
(
distDir
,
page
,
serverless
,
serverComponents
)
}
=
await
loadComponents
(
distDir
,
page
,
serverless
)
const
ampState
=
{
const
ampState
=
{
ampFirst
:
pageConfig
?.
amp
===
true
,
ampFirst
:
pageConfig
?.
amp
===
true
,
hasQuery
:
Boolean
(
query
.
amp
),
hasQuery
:
Boolean
(
query
.
amp
),
...
@@ -323,12 +321,7 @@ export default async function exportPage({
...
@@ -323,12 +321,7 @@ export default async function exportPage({
throw
new
Error
(
`Failed to render serverless page`
)
throw
new
Error
(
`Failed to render serverless page`
)
}
}
}
else
{
}
else
{
const
components
=
await
loadComponents
(
const
components
=
await
loadComponents
(
distDir
,
page
,
serverless
)
distDir
,
page
,
serverless
,
serverComponents
)
const
ampState
=
{
const
ampState
=
{
ampFirst
:
components
.
pageConfig
?.
amp
===
true
,
ampFirst
:
components
.
pageConfig
?.
amp
===
true
,
hasQuery
:
Boolean
(
query
.
amp
),
hasQuery
:
Boolean
(
query
.
amp
),
...
...
packages/next/pages/_document.tsx
View file @
24f450e8
...
@@ -585,9 +585,11 @@ export class Head extends Component<
...
@@ -585,9 +585,11 @@ export class Head extends Component<
disableOptimizedLoading
,
disableOptimizedLoading
,
optimizeCss
,
optimizeCss
,
optimizeFonts
,
optimizeFonts
,
hasConcurrentFeatures
,
runtime
,
}
=
this
.
context
}
=
this
.
context
const
hasConcurrentFeatures
=
!!
runtime
const
disableRuntimeJS
=
unstable_runtimeJS
===
false
const
disableRuntimeJS
=
unstable_runtimeJS
===
false
const
disableJsPreload
=
const
disableJsPreload
=
unstable_JsPreload
===
false
||
!
disableOptimizedLoading
unstable_JsPreload
===
false
||
!
disableOptimizedLoading
...
...
packages/next/server/dev/hot-reloader.ts
View file @
24f450e8
...
@@ -154,7 +154,6 @@ export default class HotReloader {
...
@@ -154,7 +154,6 @@ export default class HotReloader {
private
config
:
NextConfigComplete
private
config
:
NextConfigComplete
private
runtime
?:
'nodejs'
|
'edge'
private
runtime
?:
'nodejs'
|
'edge'
private
hasServerComponents
:
boolean
private
hasServerComponents
:
boolean
private
hasReactRoot
:
boolean
public
clientStats
:
webpack5
.
Stats
|
null
public
clientStats
:
webpack5
.
Stats
|
null
public
serverStats
:
webpack5
.
Stats
|
null
public
serverStats
:
webpack5
.
Stats
|
null
private
clientError
:
Error
|
null
=
null
private
clientError
:
Error
|
null
=
null
...
@@ -198,9 +197,7 @@ export default class HotReloader {
...
@@ -198,9 +197,7 @@ export default class HotReloader {
this
.
config
=
config
this
.
config
=
config
this
.
runtime
=
config
.
experimental
.
runtime
this
.
runtime
=
config
.
experimental
.
runtime
this
.
hasReactRoot
=
shouldUseReactRoot
()
this
.
hasServerComponents
=
!!
config
.
experimental
.
serverComponents
this
.
hasServerComponents
=
this
.
hasReactRoot
&&
!!
config
.
experimental
.
serverComponents
this
.
previewProps
=
previewProps
this
.
previewProps
=
previewProps
this
.
rewrites
=
rewrites
this
.
rewrites
=
rewrites
this
.
hotReloaderSpan
=
trace
(
'hot-reloader'
,
undefined
,
{
this
.
hotReloaderSpan
=
trace
(
'hot-reloader'
,
undefined
,
{
...
@@ -343,6 +340,8 @@ export default class HotReloader {
...
@@ -343,6 +340,8 @@ export default class HotReloader {
)
)
)
)
const
hasReactRoot
=
shouldUseReactRoot
()
return
webpackConfigSpan
return
webpackConfigSpan
.
traceChild
(
'generate-webpack-config'
)
.
traceChild
(
'generate-webpack-config'
)
.
traceAsyncFn
(()
=>
.
traceAsyncFn
(()
=>
...
@@ -357,7 +356,6 @@ export default class HotReloader {
...
@@ -357,7 +356,6 @@ export default class HotReloader {
rewrites
:
this
.
rewrites
,
rewrites
:
this
.
rewrites
,
entrypoints
:
entrypoints
.
client
,
entrypoints
:
entrypoints
.
client
,
runWebpackSpan
:
this
.
hotReloaderSpan
,
runWebpackSpan
:
this
.
hotReloaderSpan
,
hasReactRoot
:
this
.
hasReactRoot
,
}),
}),
getBaseWebpackConfig
(
this
.
dir
,
{
getBaseWebpackConfig
(
this
.
dir
,
{
dev
:
true
,
dev
:
true
,
...
@@ -368,10 +366,9 @@ export default class HotReloader {
...
@@ -368,10 +366,9 @@ export default class HotReloader {
rewrites
:
this
.
rewrites
,
rewrites
:
this
.
rewrites
,
entrypoints
:
entrypoints
.
server
,
entrypoints
:
entrypoints
.
server
,
runWebpackSpan
:
this
.
hotReloaderSpan
,
runWebpackSpan
:
this
.
hotReloaderSpan
,
hasReactRoot
:
this
.
hasReactRoot
,
}),
}),
// The edge runtime is only supported with React root.
// The edge runtime is only supported with React root.
this
.
hasReactRoot
hasReactRoot
?
getBaseWebpackConfig
(
this
.
dir
,
{
?
getBaseWebpackConfig
(
this
.
dir
,
{
dev
:
true
,
dev
:
true
,
isServer
:
true
,
isServer
:
true
,
...
@@ -382,7 +379,6 @@ export default class HotReloader {
...
@@ -382,7 +379,6 @@ export default class HotReloader {
rewrites
:
this
.
rewrites
,
rewrites
:
this
.
rewrites
,
entrypoints
:
entrypoints
.
edgeServer
,
entrypoints
:
entrypoints
.
edgeServer
,
runWebpackSpan
:
this
.
hotReloaderSpan
,
runWebpackSpan
:
this
.
hotReloaderSpan
,
hasReactRoot
:
this
.
hasReactRoot
,
})
})
:
null
,
:
null
,
].
filter
(
Boolean
)
as
webpack
.
Configuration
[]
].
filter
(
Boolean
)
as
webpack
.
Configuration
[]
...
@@ -421,7 +417,6 @@ export default class HotReloader {
...
@@ -421,7 +417,6 @@ export default class HotReloader {
this
.
pagesDir
this
.
pagesDir
)
)
).
client
,
).
client
,
hasReactRoot
:
this
.
hasReactRoot
,
})
})
const
fallbackCompiler
=
webpack
(
fallbackConfig
)
const
fallbackCompiler
=
webpack
(
fallbackConfig
)
...
...
packages/next/server/load-components.ts
View file @
24f450e8
...
@@ -6,7 +6,6 @@ import type {
...
@@ -6,7 +6,6 @@ import type {
import
{
import
{
BUILD_MANIFEST
,
BUILD_MANIFEST
,
REACT_LOADABLE_MANIFEST
,
REACT_LOADABLE_MANIFEST
,
MIDDLEWARE_FLIGHT_MANIFEST
,
}
from
'../shared/lib/constants'
}
from
'../shared/lib/constants'
import
{
join
}
from
'path'
import
{
join
}
from
'path'
import
{
requirePage
}
from
'./require'
import
{
requirePage
}
from
'./require'
...
@@ -31,7 +30,6 @@ export type LoadComponentsReturnType = {
...
@@ -31,7 +30,6 @@ export type LoadComponentsReturnType = {
pageConfig
:
PageConfig
pageConfig
:
PageConfig
buildManifest
:
BuildManifest
buildManifest
:
BuildManifest
reactLoadableManifest
:
ReactLoadableManifest
reactLoadableManifest
:
ReactLoadableManifest
serverComponentManifest
?:
any
|
null
Document
:
DocumentType
Document
:
DocumentType
App
:
AppType
App
:
AppType
getStaticProps
?:
GetStaticProps
getStaticProps
?:
GetStaticProps
...
@@ -63,8 +61,7 @@ export async function loadDefaultErrorComponents(distDir: string) {
...
@@ -63,8 +61,7 @@ export async function loadDefaultErrorComponents(distDir: string) {
export
async
function
loadComponents
(
export
async
function
loadComponents
(
distDir
:
string
,
distDir
:
string
,
pathname
:
string
,
pathname
:
string
,
serverless
:
boolean
,
serverless
:
boolean
serverComponents
?:
boolean
):
Promise
<
LoadComponentsReturnType
>
{
):
Promise
<
LoadComponentsReturnType
>
{
if
(
serverless
)
{
if
(
serverless
)
{
const
ComponentMod
=
await
requirePage
(
pathname
,
distDir
,
serverless
)
const
ComponentMod
=
await
requirePage
(
pathname
,
distDir
,
serverless
)
...
@@ -105,13 +102,9 @@ export async function loadComponents(
...
@@ -105,13 +102,9 @@ export async function loadComponents(
requirePage
(
pathname
,
distDir
,
serverless
),
requirePage
(
pathname
,
distDir
,
serverless
),
])
])
const
[
buildManifest
,
reactLoadableManifest
,
serverComponentManifest
]
=
const
[
buildManifest
,
reactLoadableManifest
]
=
await
Promise
.
all
([
await
Promise
.
all
([
require
(
join
(
distDir
,
BUILD_MANIFEST
)),
require
(
join
(
distDir
,
BUILD_MANIFEST
)),
require
(
join
(
distDir
,
REACT_LOADABLE_MANIFEST
)),
require
(
join
(
distDir
,
REACT_LOADABLE_MANIFEST
)),
serverComponents
?
require
(
join
(
distDir
,
'server'
,
MIDDLEWARE_FLIGHT_MANIFEST
+
'.json'
))
:
null
,
])
])
const
Component
=
interopDefault
(
ComponentMod
)
const
Component
=
interopDefault
(
ComponentMod
)
...
@@ -132,6 +125,5 @@ export async function loadComponents(
...
@@ -132,6 +125,5 @@ export async function loadComponents(
getServerSideProps
,
getServerSideProps
,
getStaticProps
,
getStaticProps
,
getStaticPaths
,
getStaticPaths
,
serverComponentManifest
,
}
}
}
}
packages/next/server/next-server.ts
View file @
24f450e8
...
@@ -693,7 +693,7 @@ export default class NextNodeServer extends BaseServer {
...
@@ -693,7 +693,7 @@ export default class NextNodeServer extends BaseServer {
}
}
protected
getServerComponentManifest
()
{
protected
getServerComponentManifest
()
{
if
(
!
this
.
nextConfig
.
experimental
.
serverComponents
)
return
undefined
if
(
!
this
.
nextConfig
.
experimental
.
runtime
)
return
undefined
return
require
(
join
(
return
require
(
join
(
this
.
distDir
,
this
.
distDir
,
'server'
,
'server'
,
...
...
packages/next/server/render.tsx
View file @
24f450e8
...
@@ -450,12 +450,12 @@ export async function renderToHTML(
...
@@ -450,12 +450,12 @@ export async function renderToHTML(
supportsDynamicHTML
,
supportsDynamicHTML
,
images
,
images
,
reactRoot
,
reactRoot
,
runtime
:
globalRuntime
,
runtime
,
ComponentMod
,
ComponentMod
,
AppMod
,
AppMod
,
}
=
renderOpts
}
=
renderOpts
const
hasConcurrentFeatures
=
reactRoot
const
hasConcurrentFeatures
=
!!
runtime
let
Document
=
renderOpts
.
Document
let
Document
=
renderOpts
.
Document
const
OriginalComponent
=
renderOpts
.
Component
const
OriginalComponent
=
renderOpts
.
Component
...
@@ -464,7 +464,7 @@ export async function renderToHTML(
...
@@ -464,7 +464,7 @@ export async function renderToHTML(
const
isServerComponent
=
const
isServerComponent
=
!!
serverComponentManifest
&&
!!
serverComponentManifest
&&
hasConcurrentFeatures
&&
hasConcurrentFeatures
&&
!!
ComponentMod
.
__next_rsc__
ComponentMod
.
__next_rsc__
let
Component
:
React
.
ComponentType
<
{}
>
|
((
props
:
any
)
=>
JSX
.
Element
)
=
let
Component
:
React
.
ComponentType
<
{}
>
|
((
props
:
any
)
=>
JSX
.
Element
)
=
renderOpts
.
Component
renderOpts
.
Component
...
@@ -1243,7 +1243,7 @@ export async function renderToHTML(
...
@@ -1243,7 +1243,7 @@ export async function renderToHTML(
|
typeof
Document
|
typeof
Document
|
undefined
|
undefined
if
(
process
.
browser
&&
Document
.
getInitialProps
)
{
if
(
runtime
===
'edge'
&&
Document
.
getInitialProps
)
{
// In the Edge runtime, `Document.getInitialProps` isn't supported.
// In the Edge runtime, `Document.getInitialProps` isn't supported.
// We throw an error here if it's customized.
// We throw an error here if it's customized.
if
(
!
builtinDocument
)
{
if
(
!
builtinDocument
)
{
...
@@ -1329,8 +1329,7 @@ export async function renderToHTML(
...
@@ -1329,8 +1329,7 @@ export async function renderToHTML(
)
:
(
)
:
(
<
Body
>
<
Body
>
<
AppContainerWithIsomorphicFiberStructure
>
<
AppContainerWithIsomorphicFiberStructure
>
{
isServerComponent
&&
AppMod
.
__next_rsc__
?
(
{
renderOpts
.
serverComponents
&&
AppMod
.
__next_rsc__
?
(
// _app.server.js is used.
<
Component
{
...
props
.
pageProps
}
router=
{
router
}
/>
<
Component
{
...
props
.
pageProps
}
router=
{
router
}
/>
)
:
(
)
:
(
<
App
{
...
props
}
Component=
{
Component
}
router=
{
router
}
/>
<
App
{
...
props
}
Component=
{
Component
}
router=
{
router
}
/>
...
@@ -1362,6 +1361,7 @@ export async function renderToHTML(
...
@@ -1362,6 +1361,7 @@ export async function renderToHTML(
),
),
generateStaticHTML
:
true
,
generateStaticHTML
:
true
,
})
})
const
flushed
=
await
streamToString
(
flushEffectStream
)
const
flushed
=
await
streamToString
(
flushEffectStream
)
return
flushed
return
flushed
}
}
...
@@ -1489,8 +1489,7 @@ export async function renderToHTML(
...
@@ -1489,8 +1489,7 @@ export async function renderToHTML(
optimizeCss
:
renderOpts
.
optimizeCss
,
optimizeCss
:
renderOpts
.
optimizeCss
,
optimizeFonts
:
renderOpts
.
optimizeFonts
,
optimizeFonts
:
renderOpts
.
optimizeFonts
,
nextScriptWorkers
:
renderOpts
.
nextScriptWorkers
,
nextScriptWorkers
:
renderOpts
.
nextScriptWorkers
,
runtime
:
globalRuntime
,
runtime
,
hasConcurrentFeatures
,
}
}
const
document
=
(
const
document
=
(
...
...
packages/next/shared/lib/html-context.ts
View file @
24f450e8
...
@@ -38,7 +38,6 @@ export type HtmlProps = {
...
@@ -38,7 +38,6 @@ export type HtmlProps = {
optimizeFonts
?:
boolean
optimizeFonts
?:
boolean
nextScriptWorkers
?:
boolean
nextScriptWorkers
?:
boolean
runtime
?:
'edge'
|
'nodejs'
runtime
?:
'edge'
|
'nodejs'
hasConcurrentFeatures
?:
boolean
}
}
export
const
HtmlContext
=
createContext
<
HtmlProps
>
(
null
as
any
)
export
const
HtmlContext
=
createContext
<
HtmlProps
>
(
null
as
any
)
...
...
test/integration/react-18-invalid-config/index.test.js
View file @
24f450e8
...
@@ -25,6 +25,19 @@ describe('Invalid react 18 webpack config', () => {
...
@@ -25,6 +25,19 @@ describe('Invalid react 18 webpack config', () => {
)
)
})
})
it
(
'should require `experimental.runtime` for server components'
,
async
()
=>
{
writeNextConfig
({
reactRoot
:
true
,
serverComponents
:
true
,
})
const
{
stderr
}
=
await
nextBuild
(
appDir
,
[],
{
stderr
:
true
})
nextConfig
.
restore
()
expect
(
stderr
).
toContain
(
'`experimental.runtime` is required to be set along with `experimental.serverComponents`.'
)
})
it
(
'should warn user when not using react 18 and `experimental.reactRoot` is enabled'
,
async
()
=>
{
it
(
'should warn user when not using react 18 and `experimental.reactRoot` is enabled'
,
async
()
=>
{
const
reactDomPackagePah
=
join
(
appDir
,
'node_modules/react-dom'
)
const
reactDomPackagePah
=
join
(
appDir
,
'node_modules/react-dom'
)
await
fs
.
mkdirp
(
reactDomPackagePah
)
await
fs
.
mkdirp
(
reactDomPackagePah
)
...
...
test/integration/react-18/app/pages/suspense/no-preload.js
View file @
24f450e8
...
@@ -2,7 +2,6 @@ import { Suspense } from 'react'
...
@@ -2,7 +2,6 @@ import { Suspense } from 'react'
import
dynamic
from
'next/dynamic'
import
dynamic
from
'next/dynamic'
const
Bar
=
dynamic
(()
=>
import
(
'../../components/bar'
),
{
const
Bar
=
dynamic
(()
=>
import
(
'../../components/bar'
),
{
ssr
:
false
,
suspense
:
true
,
suspense
:
true
,
// Explicitly declare loaded modules.
// Explicitly declare loaded modules.
// For suspense cases, they'll be ignored.
// For suspense cases, they'll be ignored.
...
@@ -15,7 +14,7 @@ const Bar = dynamic(() => import('../../components/bar'), {
...
@@ -15,7 +14,7 @@ const Bar = dynamic(() => import('../../components/bar'), {
export
default
function
NoPreload
()
{
export
default
function
NoPreload
()
{
return
(
return
(
<
Suspense
fallback
=
{
'
fallback
'
}
>
<
Suspense
fallback
=
{
'
rab
'
}
>
<
Bar
/>
<
Bar
/>
<
/Suspense
>
<
/Suspense
>
)
)
...
...
test/integration/react-18/test/basics.js
View file @
24f450e8
...
@@ -31,7 +31,7 @@ export default (context) => {
...
@@ -31,7 +31,7 @@ export default (context) => {
const
nextData
=
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
text
())
const
nextData
=
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
text
())
const
content
=
$
(
'#__next'
).
text
()
const
content
=
$
(
'#__next'
).
text
()
// <Bar> is suspended
// <Bar> is suspended
expect
(
content
).
toBe
(
'
fallback
'
)
expect
(
content
).
toBe
(
'
rab
'
)
expect
(
nextData
.
dynamicIds
).
toBeUndefined
()
expect
(
nextData
.
dynamicIds
).
toBeUndefined
()
})
})
...
...
test/integration/react-18/test/blocking.js
View file @
24f450e8
...
@@ -8,16 +8,15 @@ export default (context, render) => {
...
@@ -8,16 +8,15 @@ export default (context, render) => {
return
cheerio
.
load
(
html
)
return
cheerio
.
load
(
html
)
}
}
it
(
'should render fallback on server side if suspense without
ssr
'
,
async
()
=>
{
it
(
'should render fallback on server side if suspense without
preload
'
,
async
()
=>
{
const
$
=
await
get
$
(
'/suspense/no-preload'
)
const
$
=
await
get
$
(
'/suspense/no-preload'
)
const
nextData
=
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
text
())
const
nextData
=
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
text
())
const
content
=
$
(
'#__next'
).
text
()
const
content
=
$
(
'#__next'
).
text
()
expect
(
content
).
toBe
(
'
fallback
'
)
expect
(
content
).
toBe
(
'
rab
'
)
expect
(
nextData
.
dynamicIds
).
toBeUndefined
()
expect
(
nextData
.
dynamicIds
).
toBeUndefined
()
})
})
// Testing the same thing as above.
it
(
'should render fallback on server side if suspended on server with preload'
,
async
()
=>
{
it
.
skip
(
'should render import fallback on server side if suspended without ssr'
,
async
()
=>
{
const
$
=
await
get
$
(
'/suspense/thrown'
)
const
$
=
await
get
$
(
'/suspense/thrown'
)
const
html
=
$
(
'body'
).
html
()
const
html
=
$
(
'body'
).
html
()
expect
(
html
).
toContain
(
'loading'
)
expect
(
html
).
toContain
(
'loading'
)
...
...
test/integration/react-streaming-and-server-components/app/pages/err/render.js
View file @
24f450e8
...
@@ -5,7 +5,3 @@ export default function MyError() {
...
@@ -5,7 +5,3 @@ export default function MyError() {
throw
new
Error
(
'oops'
)
throw
new
Error
(
'oops'
)
}
}
}
}
export
const
config
=
{
runtime
:
'edge'
,
}
test/integration/react-streaming-and-server-components/app/pages/err/suspense.js
View file @
24f450e8
...
@@ -18,7 +18,3 @@ export default function page() {
...
@@ -18,7 +18,3 @@ export default function page() {
<
/
>
<
/
>
)
)
}
}
export
const
config
=
{
runtime
:
'edge'
,
}
test/integration/react-streaming-and-server-components/app/pages/next-api/image.server.js
View file @
24f450e8
...
@@ -7,7 +7,3 @@ const Page = () => {
...
@@ -7,7 +7,3 @@ const Page = () => {
}
}
export
default
Page
export
default
Page
export
const
config
=
{
runtime
:
'edge'
,
}
test/integration/react-streaming-and-server-components/app/pages/next-api/link.server.js
View file @
24f450e8
...
@@ -16,7 +16,3 @@ export default function LinkPage({ router }) {
...
@@ -16,7 +16,3 @@ export default function LinkPage({ router }) {
<
/
>
<
/
>
)
)
}
}
export
const
config
=
{
runtime
:
'edge'
,
}
test/integration/react-streaming-and-server-components/app/pages/partial-hydration.server.js
View file @
24f450e8
...
@@ -40,7 +40,3 @@ export default function () {
...
@@ -40,7 +40,3 @@ export default function () {
<
/
>
<
/
>
)
)
}
}
export
const
config
=
{
runtime
:
'edge'
,
}
test/integration/react-streaming-and-server-components/app/pages/routes/[dynamic].server.js
View file @
24f450e8
export
default
function
Pid
({
router
})
{
export
default
function
Pid
({
router
})
{
return
<
div
>
{
`query:
${
router
.
query
.
dynamic
}
`
}
<
/div
>
return
<
div
>
{
`query:
${
router
.
query
.
dynamic
}
`
}
<
/div
>
}
}
export
const
config
=
{
runtime
:
'edge'
,
}
test/integration/react-streaming-and-server-components/app/pages/streaming-rsc.server.js
View file @
24f450e8
...
@@ -29,7 +29,3 @@ export default function Page() {
...
@@ -29,7 +29,3 @@ export default function Page() {
<
/div
>
<
/div
>
)
)
}
}
export
const
config
=
{
runtime
:
'edge'
,
}
test/integration/react-streaming-and-server-components/app/pages/streaming.js
View file @
24f450e8
...
@@ -21,7 +21,3 @@ export default function Page() {
...
@@ -21,7 +21,3 @@ export default function Page() {
<
/Suspense
>
<
/Suspense
>
)
)
}
}
export
const
config
=
{
runtime
:
'edge'
,
}
test/integration/react-streaming-and-server-components/switchable-runtime/next.config.js
deleted
100644 → 0
View file @
52e34ced
const
withReact18
=
require
(
'../../react-18/test/with-react-18'
)
module
.
exports
=
withReact18
({
reactStrictMode
:
true
,
experimental
:
{
serverComponents
:
true
,
// runtime: 'edge',
},
})
test/integration/react-streaming-and-server-components/switchable-runtime/package.json
deleted
100644 → 0
View file @
52e34ced
{
"private"
:
true
,
"scripts"
:
{
"lnext"
:
"node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next"
,
"dev"
:
"yarn lnext dev"
,
"build"
:
"yarn lnext build"
,
"start"
:
"yarn lnext start"
}
}
test/integration/react-streaming-and-server-components/switchable-runtime/pages-manifest.json
deleted
100644 → 0
View file @
52e34ced
{
"/_app"
:
"pages/_app.js"
,
"/_error"
:
"pages/_error.js"
,
"/edge-rsc"
:
"pages/edge-rsc.js"
,
"/static"
:
"pages/static.js"
,
"/node-rsc"
:
"pages/node-rsc.js"
,
"/node"
:
"pages/node.js"
,
"/edge"
:
"pages/edge.js"
}
test/integration/react-streaming-and-server-components/switchable-runtime/pages/edge-rsc.server.js
deleted
100644 → 0
View file @
52e34ced
import
getRuntime
from
'../utils/runtime'
import
getTime
from
'../utils/time'
export
default
function
Page
()
{
return
(
<
div
>
This
is
a
SSR
RSC
page
.
<
br
/>
{
'Runtime: '
+
getRuntime
()}
<
br
/>
{
'Time: '
+
getTime
()}
<
/div
>
)
}
export
const
config
=
{
runtime
:
'edge'
,
}
test/integration/react-streaming-and-server-components/switchable-runtime/pages/edge.js
deleted
100644 → 0
View file @
52e34ced
import
getRuntime
from
'../utils/runtime'
import
getTime
from
'../utils/time'
export
default
function
Page
()
{
return
(
<
div
>
This
is
a
SSR
page
.
<
br
/>
{
'Runtime: '
+
getRuntime
()}
<
br
/>
{
'Time: '
+
getTime
()}
<
/div
>
)
}
export
const
config
=
{
runtime
:
'edge'
,
}
test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc-ssg.server.js
deleted
100644 → 0
View file @
52e34ced
import
getRuntime
from
'../utils/runtime'
import
getTime
from
'../utils/time'
export
default
function
Page
({
type
})
{
return
(
<
div
>
This
is
a
{
type
}
RSC
page
.
<
br
/>
{
'Runtime: '
+
getRuntime
()}
<
br
/>
{
'Time: '
+
getTime
()}
<
/div
>
)
}
export
function
getStaticProps
()
{
return
{
props
:
{
type
:
'SSG'
,
},
}
}
export
const
config
=
{
runtime
:
'nodejs'
,
}
test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc-ssr.server.js
deleted
100644 → 0
View file @
52e34ced
import
getRuntime
from
'../utils/runtime'
import
getTime
from
'../utils/time'
export
default
function
Page
({
type
})
{
return
(
<
div
>
This
is
a
{
type
}
RSC
page
.
<
br
/>
{
'Runtime: '
+
getRuntime
()}
<
br
/>
{
'Time: '
+
getTime
()}
<
/div
>
)
}
export
function
getServerSideProps
()
{
return
{
props
:
{
type
:
'SSR'
,
},
}
}
export
const
config
=
{
runtime
:
'nodejs'
,
}
test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-rsc.server.js
deleted
100644 → 0
View file @
52e34ced
import
getRuntime
from
'../utils/runtime'
import
getTime
from
'../utils/time'
export
default
function
Page
()
{
return
(
<
div
>
This
is
a
static
RSC
page
.
<
br
/>
{
'Runtime: '
+
getRuntime
()}
<
br
/>
{
'Time: '
+
getTime
()}
<
/div
>
)
}
export
const
config
=
{
runtime
:
'nodejs'
,
}
test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-ssg.js
deleted
100644 → 0
View file @
52e34ced
import
getRuntime
from
'../utils/runtime'
import
getTime
from
'../utils/time'
export
default
function
Page
({
type
})
{
return
(
<
div
>
This
is
a
{
type
}
page
.
<
br
/>
{
'Runtime: '
+
getRuntime
()}
<
br
/>
{
'Time: '
+
getTime
()}
<
/div
>
)
}
export
function
getStaticProps
()
{
return
{
props
:
{
type
:
'SSG'
,
},
}
}
export
const
config
=
{
runtime
:
'nodejs'
,
}
test/integration/react-streaming-and-server-components/switchable-runtime/pages/node-ssr.js
deleted
100644 → 0
View file @
52e34ced
import
getRuntime
from
'../utils/runtime'
import
getTime
from
'../utils/time'
export
default
function
Page
({
type
})
{
return
(
<
div
>
This
is
a
{
type
}
page
.
<
br
/>
{
'Runtime: '
+
getRuntime
()}
<
br
/>
{
'Time: '
+
getTime
()}
<
/div
>
)
}
export
function
getServerSideProps
()
{
return
{
props
:
{
type
:
'SSR'
,
},
}
}
export
const
config
=
{
runtime
:
'nodejs'
,
}
test/integration/react-streaming-and-server-components/switchable-runtime/pages/node.js
deleted
100644 → 0
View file @
52e34ced
import
getRuntime
from
'../utils/runtime'
import
getTime
from
'../utils/time'
export
default
function
Page
()
{
return
(
<
div
>
This
is
a
static
page
.
<
br
/>
{
'Runtime: '
+
getRuntime
()}
<
br
/>
{
'Time: '
+
getTime
()}
<
/div
>
)
}
export
const
config
=
{
runtime
:
'nodejs'
,
}
test/integration/react-streaming-and-server-components/switchable-runtime/pages/static.js
deleted
100644 → 0
View file @
52e34ced
import
getRuntime
from
'../utils/runtime'
import
getTime
from
'../utils/time'
export
default
function
Page
()
{
return
(
<
div
>
This
is
a
static
page
.
<
br
/>
{
'Runtime: '
+
getRuntime
()}
<
br
/>
{
'Time: '
+
getTime
()}
<
/div
>
)
}
test/integration/react-streaming-and-server-components/switchable-runtime/utils/runtime.js
deleted
100644 → 0
View file @
52e34ced
export
default
function
getRuntime
()
{
return
process
.
version
?
`Node.js
${
process
.
version
}
`
:
'Edge/Browser'
}
test/integration/react-streaming-and-server-components/switchable-runtime/utils/time.js
deleted
100644 → 0
View file @
52e34ced
export
default
function
getTime
()
{
return
Date
.
now
()
}
test/integration/react-streaming-and-server-components/test/switchable-runtime.test.js
deleted
100644 → 0
View file @
52e34ced
/* eslint-env jest */
import
{
join
}
from
'path'
import
{
// File,
nextBuild
as
_nextBuild
,
nextStart
as
_nextStart
,
}
from
'next-test-utils'
import
{
findPort
,
killApp
,
renderViaHTTP
}
from
'next-test-utils'
const
nodeArgs
=
[
'-r'
,
join
(
__dirname
,
'../../react-18/test/require-hook.js'
)]
const
appDir
=
join
(
__dirname
,
'../switchable-runtime'
)
// const nextConfig = new File(join(appDir, 'next.config.js'))
async
function
nextBuild
(
dir
,
options
)
{
return
await
_nextBuild
(
dir
,
[],
{
...
options
,
stdout
:
true
,
stderr
:
true
,
nodeArgs
,
})
}
async
function
nextStart
(
dir
,
port
)
{
return
await
_nextStart
(
dir
,
port
,
{
stdout
:
true
,
stderr
:
true
,
nodeArgs
,
})
}
async
function
testRoute
(
appPort
,
url
,
{
isStatic
,
isEdge
})
{
const
html1
=
await
renderViaHTTP
(
appPort
,
url
)
const
renderedAt1
=
+
html1
.
match
(
/Time:
(\d
+
)
/
)[
1
]
expect
(
html1
).
toContain
(
`Runtime:
${
isEdge
?
'Edge'
:
'Node.js'
}
`
)
const
html2
=
await
renderViaHTTP
(
appPort
,
url
)
const
renderedAt2
=
+
html2
.
match
(
/Time:
(\d
+
)
/
)[
1
]
expect
(
html2
).
toContain
(
`Runtime:
${
isEdge
?
'Edge'
:
'Node.js'
}
`
)
if
(
isStatic
)
{
// Should not be re-rendered, some timestamp should be returned.
expect
(
renderedAt1
).
toBe
(
renderedAt2
)
}
else
{
// Should be re-rendered.
expect
(
renderedAt1
).
toBeLessThan
(
renderedAt2
)
}
}
describe
(
'Without global runtime configuration'
,
()
=>
{
const
context
=
{
appDir
}
beforeAll
(
async
()
=>
{
context
.
appPort
=
await
findPort
()
const
{
stderr
}
=
await
nextBuild
(
context
.
appDir
)
context
.
stderr
=
stderr
context
.
server
=
await
nextStart
(
context
.
appDir
,
context
.
appPort
)
})
afterAll
(
async
()
=>
{
await
killApp
(
context
.
server
)
})
it
(
'should build /static as a static page with the nodejs runtime'
,
async
()
=>
{
await
testRoute
(
context
.
appPort
,
'/static'
,
{
isStatic
:
true
,
isEdge
:
false
,
})
})
it
(
'should build /node as a static page with the nodejs runtime'
,
async
()
=>
{
await
testRoute
(
context
.
appPort
,
'/node'
,
{
isStatic
:
true
,
isEdge
:
false
,
})
})
it
(
'should build /node-ssr as a dynamic page with the nodejs runtime'
,
async
()
=>
{
await
testRoute
(
context
.
appPort
,
'/node-ssr'
,
{
isStatic
:
false
,
isEdge
:
false
,
})
})
it
(
'should build /node-ssg as a static page with the nodejs runtime'
,
async
()
=>
{
await
testRoute
(
context
.
appPort
,
'/node-ssg'
,
{
isStatic
:
true
,
isEdge
:
false
,
})
})
it
(
'should build /node-rsc as a static page with the nodejs runtime'
,
async
()
=>
{
await
testRoute
(
context
.
appPort
,
'/node-rsc'
,
{
isStatic
:
true
,
isEdge
:
false
,
})
})
it
(
'should build /node-rsc-ssr as a dynamic page with the nodejs runtime'
,
async
()
=>
{
await
testRoute
(
context
.
appPort
,
'/node-rsc-ssr'
,
{
isStatic
:
false
,
isEdge
:
false
,
})
})
it
(
'should build /node-rsc-ssg as a static page with the nodejs runtime'
,
async
()
=>
{
await
testRoute
(
context
.
appPort
,
'/node-rsc-ssg'
,
{
isStatic
:
true
,
isEdge
:
false
,
})
})
it
(
'should build /edge as a dynamic page with the edge runtime'
,
async
()
=>
{
await
testRoute
(
context
.
appPort
,
'/edge'
,
{
isStatic
:
false
,
isEdge
:
true
,
})
})
it
(
'should build /edge-rsc as a dynamic page with the edge runtime'
,
async
()
=>
{
await
testRoute
(
context
.
appPort
,
'/edge-rsc'
,
{
isStatic
:
false
,
isEdge
:
true
,
})
})
})
test/integration/react-streaming-and-server-components/unsupported-native-module/next.config.js
View file @
24f450e8
...
@@ -3,6 +3,7 @@ const withReact18 = require('../../react-18/test/with-react-18')
...
@@ -3,6 +3,7 @@ const withReact18 = require('../../react-18/test/with-react-18')
module
.
exports
=
withReact18
({
module
.
exports
=
withReact18
({
experimental
:
{
experimental
:
{
reactRoot
:
true
,
reactRoot
:
true
,
runtime
:
'edge'
,
serverComponents
:
true
,
serverComponents
:
true
,
},
},
})
})
test/integration/react-streaming-and-server-components/unsupported-native-module/pages/index.js
View file @
24f450e8
...
@@ -8,7 +8,3 @@ export default function Index() {
...
@@ -8,7 +8,3 @@ export default function Index() {
console
.
log
(
EOF
)
console
.
log
(
EOF
)
return
'Access Node.js native module dns'
return
'Access Node.js native module dns'
}
}
export
const
config
=
{
runtime
:
'edge'
,
}
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