Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate concurrentFeatures with runtime #34068

Merged
merged 22 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export function createPagesMapping(
{
isDev,
hasServerComponents,
hasConcurrentFeatures,
runtime,
}: {
isDev: boolean
hasServerComponents: boolean
hasConcurrentFeatures: boolean
runtime?: 'nodejs' | 'edge'
}
): PagesMapping {
const previousPages: PagesMapping = {}
Expand Down Expand Up @@ -81,7 +81,7 @@ export function createPagesMapping(
// we alias these in development and allow webpack to
// allow falling back to the correct source file so
// that HMR can work properly when a file is added/removed
const documentPage = `_document${hasConcurrentFeatures ? '-web' : ''}`
const documentPage = `_document${runtime ? '-concurrent' : ''}`
if (isDev) {
pages['/_app'] = `${PAGES_DIR_ALIAS}/_app`
pages['/_error'] = `${PAGES_DIR_ALIAS}/_error`
Expand All @@ -98,7 +98,7 @@ export function createPagesMapping(
type Entrypoints = {
client: webpack5.EntryObject
server: webpack5.EntryObject
serverWeb: webpack5.EntryObject
edgeServer: webpack5.EntryObject
}

export function createEntrypoints(
Expand All @@ -111,7 +111,7 @@ export function createEntrypoints(
): Entrypoints {
const client: webpack5.EntryObject = {}
const server: webpack5.EntryObject = {}
const serverWeb: webpack5.EntryObject = {}
const edgeServer: webpack5.EntryObject = {}

const hasRuntimeConfig =
Object.keys(config.publicRuntimeConfig).length > 0 ||
Expand Down Expand Up @@ -156,7 +156,7 @@ export function createEntrypoints(
const isCustomError = isCustomErrorPage(page)
const isFlight = isFlightPage(config, absolutePagePath)

const webServerRuntime = !!config.experimental.concurrentFeatures
const edgeRuntime = config.experimental.runtime === 'edge'

if (page.match(MIDDLEWARE_ROUTE)) {
const loaderOpts: MiddlewareLoaderOptions = {
Expand All @@ -170,9 +170,9 @@ export function createEntrypoints(
return
}

if (webServerRuntime && !isReserved && !isCustomError && !isApiRoute) {
if (edgeRuntime && !isReserved && !isCustomError && !isApiRoute) {
ssrEntries.set(clientBundlePath, { requireFlightManifest: isFlight })
serverWeb[serverBundlePath] = finalizeEntrypoint({
edgeServer[serverBundlePath] = finalizeEntrypoint({
name: '[name].js',
value: `next-middleware-ssr-loader?${stringify({
dev: false,
Expand All @@ -184,7 +184,7 @@ export function createEntrypoints(
...defaultServerlessOptions,
} as any)}!`,
isServer: false,
isServerWeb: true,
isEdgeServer: true,
})
}

Expand All @@ -198,14 +198,14 @@ export function createEntrypoints(
serverlessLoaderOptions
)}!`
} else if (isApiRoute || target === 'server') {
if (!webServerRuntime || isReserved || isCustomError) {
if (!edgeRuntime || isReserved || isCustomError) {
server[serverBundlePath] = [absolutePagePath]
}
} else if (
isLikeServerless &&
page !== '/_app' &&
page !== '/_document' &&
!webServerRuntime
!edgeRuntime
) {
const serverlessLoaderOptions: ServerlessLoaderQuery = {
page,
Expand Down Expand Up @@ -244,7 +244,7 @@ export function createEntrypoints(
return {
client,
server,
serverWeb,
edgeServer,
}
}

Expand All @@ -253,13 +253,13 @@ export function finalizeEntrypoint({
value,
isServer,
isMiddleware,
isServerWeb,
isEdgeServer,
}: {
isServer: boolean
name: string
value: ObjectValue<webpack5.EntryObject>
isMiddleware?: boolean
isServerWeb?: boolean
isEdgeServer?: boolean
}): ObjectValue<webpack5.EntryObject> {
const entry =
typeof value !== 'object' || Array.isArray(value)
Expand All @@ -276,7 +276,7 @@ export function finalizeEntrypoint({
}
}

if (isServerWeb) {
if (isEdgeServer) {
const ssrMiddlewareEntry = {
library: {
name: ['_ENTRIES', `middleware_[name]`],
Expand Down
22 changes: 13 additions & 9 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ export default async function build(
setGlobal('phase', PHASE_PRODUCTION_BUILD)
setGlobal('distDir', distDir)

const hasConcurrentFeatures = !!config.experimental.concurrentFeatures
// Currently, when the runtime option is set (either `nodejs` or `edge`),
// we enable concurrent features (Fizz-related rendering architecture).
const runtime = config.experimental.runtime
const hasConcurrentFeatures = !!runtime

const hasServerComponents =
hasConcurrentFeatures && !!config.experimental.serverComponents

Expand Down Expand Up @@ -292,7 +296,7 @@ export default async function build(
createPagesMapping(pagePaths, config.pageExtensions, {
isDev: false,
hasServerComponents,
hasConcurrentFeatures,
runtime,
})
)

Expand Down Expand Up @@ -607,16 +611,16 @@ export default async function build(
rewrites,
runWebpackSpan,
}),
hasConcurrentFeatures
runtime === 'edge'
? getBaseWebpackConfig(dir, {
buildId,
reactProductionProfiling,
isServer: true,
webServerRuntime: true,
isEdgeRuntime: true,
config,
target,
pagesDir,
entrypoints: entrypoints.serverWeb,
entrypoints: entrypoints.edgeServer,
rewrites,
runWebpackSpan,
})
Expand Down Expand Up @@ -650,20 +654,20 @@ export default async function build(
}
} else {
const serverResult = await runCompiler(configs[1], { runWebpackSpan })
const serverWebResult = configs[2]
const edgeServerResult = configs[2]
? await runCompiler(configs[2], { runWebpackSpan })
: null

result = {
warnings: [
...clientResult.warnings,
...serverResult.warnings,
...(serverWebResult?.warnings || []),
...(edgeServerResult?.warnings || []),
],
errors: [
...clientResult.errors,
...serverResult.errors,
...(serverWebResult?.errors || []),
...(edgeServerResult?.errors || []),
],
}
}
Expand Down Expand Up @@ -710,7 +714,7 @@ export default async function build(
const moduleName = getUnresolvedModuleFromError(error)
if (hasConcurrentFeatures && moduleName) {
const err = new Error(
`Native Node.js APIs are not supported in the Edge Runtime with \`concurrentFeatures\` enabled. Found \`${moduleName}\` imported.\n\n`
`Native Node.js APIs are not supported in the Edge Runtime. Found \`${moduleName}\` imported.\n\n`
) as NextError
err.code = 'EDGE_RUNTIME_UNSUPPORTED_API'
throw err
Expand Down
44 changes: 22 additions & 22 deletions packages/next/build/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function startedDevelopmentServer(appUrl: string, bindAddr: string) {

let previousClient: webpack5.Compiler | null = null
let previousServer: webpack5.Compiler | null = null
let previousServerWeb: webpack5.Compiler | null = null
let previousEdgeServer: webpack5.Compiler | null = null

type CompilerDiagnostics = {
modules: number
Expand All @@ -39,7 +39,7 @@ export type AmpPageStatus = {
type BuildStatusStore = {
client: WebpackStatus
server: WebpackStatus
serverWeb?: WebpackStatus
edgeServer?: WebpackStatus
trigger: string | undefined
amp: AmpPageStatus
}
Expand Down Expand Up @@ -102,14 +102,14 @@ const buildStore = createStore<BuildStatusStore>()
let buildWasDone = false
let clientWasLoading = true
let serverWasLoading = true
let serverWebWasLoading = false
let edgeServerWasLoading = false

buildStore.subscribe((state) => {
const { amp, client, server, serverWeb, trigger } = state
const { amp, client, server, edgeServer, trigger } = state

const { appUrl } = consoleStore.getState()

if (client.loading || server.loading || serverWeb?.loading) {
if (client.loading || server.loading || edgeServer?.loading) {
consoleStore.setState(
{
bootstrap: false,
Expand All @@ -121,12 +121,12 @@ buildStore.subscribe((state) => {
)
clientWasLoading = (!buildWasDone && clientWasLoading) || client.loading
serverWasLoading = (!buildWasDone && serverWasLoading) || server.loading
serverWebWasLoading =
(!buildWasDone && serverWasLoading) || !!serverWeb?.loading
edgeServerWasLoading =
(!buildWasDone && serverWasLoading) || !!edgeServer?.loading
buildWasDone = false
return
}
if (serverWeb?.loading) return
if (edgeServer?.loading) return

buildWasDone = true

Expand All @@ -136,14 +136,14 @@ buildStore.subscribe((state) => {
loading: false,
typeChecking: false,
partial:
clientWasLoading && (serverWasLoading || serverWebWasLoading)
clientWasLoading && (serverWasLoading || edgeServerWasLoading)
? 'client and server'
: undefined,
modules:
(clientWasLoading ? client.modules : 0) +
(serverWasLoading ? server.modules : 0) +
(serverWebWasLoading ? serverWeb?.modules || 0 : 0),
hasServerWeb: !!serverWeb,
(edgeServerWasLoading ? edgeServer?.modules || 0 : 0),
hasEdgeServer: !!edgeServer,
}
if (client.errors) {
// Show only client errors
Expand All @@ -165,12 +165,12 @@ buildStore.subscribe((state) => {
} as OutputState,
true
)
} else if (serverWeb && serverWeb.errors) {
// Show only serverWeb errors
} else if (edgeServer && edgeServer.errors) {
// Show only edge server errors
consoleStore.setState(
{
...partialState,
errors: serverWeb.errors,
errors: edgeServer.errors,
warnings: null,
} as OutputState,
true
Expand All @@ -180,7 +180,7 @@ buildStore.subscribe((state) => {
const warnings = [
...(client.warnings || []),
...(server.warnings || []),
...((serverWeb && serverWeb.warnings) || []),
...((edgeServer && edgeServer.warnings) || []),
].concat(formatAmpMessages(amp) || [])

consoleStore.setState(
Expand Down Expand Up @@ -223,20 +223,20 @@ export function ampValidation(
export function watchCompilers(
client: webpack5.Compiler,
server: webpack5.Compiler,
serverWeb: webpack5.Compiler
edgeServer: webpack5.Compiler
) {
if (
previousClient === client &&
previousServer === server &&
previousServerWeb === serverWeb
previousEdgeServer === edgeServer
) {
return
}

buildStore.setState({
client: { loading: true },
server: { loading: true },
serverWeb: serverWeb ? { loading: true } : undefined,
edgeServer: edgeServer ? { loading: true } : undefined,
trigger: 'initial',
})

Expand Down Expand Up @@ -295,18 +295,18 @@ export function watchCompilers(
})
}
})
if (serverWeb) {
tapCompiler('serverWeb', serverWeb, (status) => {
if (edgeServer) {
tapCompiler('edgeServer', edgeServer, (status) => {
buildStore.setState({
serverWeb: status,
edgeServer: status,
trigger: undefined,
})
})
}

previousClient = client
previousServer = server
previousServerWeb = serverWeb
previousEdgeServer = edgeServer
}

export function reportTrigger(trigger: string) {
Expand Down
6 changes: 3 additions & 3 deletions packages/next/build/output/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type OutputState =
modules: number
errors: string[] | null
warnings: string[] | null
hasServerWeb: boolean
hasEdgeServer: boolean
}
))

Expand Down Expand Up @@ -91,9 +91,9 @@ store.subscribe((state) => {
}

const moduleName = getUnresolvedModuleFromError(cleanError)
if (state.hasServerWeb && moduleName) {
if (state.hasEdgeServer && moduleName) {
console.error(
`Native Node.js APIs are not supported in the Edge Runtime with \`concurrentFeatures\` enabled. Found \`${moduleName}\` imported.\n`
`Native Node.js APIs are not supported in the Edge Runtime. Found \`${moduleName}\` imported.\n`
)
return
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ export function isFlightPage(
if (
!(
nextConfig.experimental.serverComponents &&
nextConfig.experimental.concurrentFeatures
nextConfig.experimental.runtime
)
)
return false
Expand Down
Loading