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

Rename experimentalReact #49046

Merged
merged 2 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ export default async function build(
...process.env,
__NEXT_PRIVATE_PREBUNDLED_REACT:
type === 'app'
? config.experimental.experimentalReact
? config.experimental.serverActions
? 'experimental'
: 'next'
: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ ${
// to ensure the correctness of the version for app.
`\
if (nextConfig && nextConfig.experimental && nextConfig.experimental.appDir) {
process.env.__NEXT_PRIVATE_PREBUNDLED_REACT = nextConfig.experimental.experimentalReact ? 'experimental' : 'next'
process.env.__NEXT_PRIVATE_PREBUNDLED_REACT = nextConfig.experimental.serverActions ? 'experimental' : 'next'
}
`
}
Expand Down
6 changes: 3 additions & 3 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,8 @@ export default async function getBaseWebpackConfig(
const hasServerComponents = hasAppDir
const disableOptimizedLoading = true
const enableTypedRoutes = !!config.experimental.typedRoutes && hasAppDir
const experimentalReact = !!config.experimental.experimentalReact && hasAppDir
const bundledReactChannel = experimentalReact ? '-experimental' : ''
const serverActions = !!config.experimental.serverActions && hasAppDir
const bundledReactChannel = serverActions ? '-experimental' : ''

if (isClient) {
if (
Expand Down Expand Up @@ -2307,7 +2307,7 @@ export default async function getBaseWebpackConfig(
appDir,
dev,
isEdgeServer,
useExperimentalReact: experimentalReact,
useServerActions: serverActions,
})),
hasAppDir &&
!isClient &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ import {
import { traverseModules, forEachEntryModule } from '../utils'
import { normalizePathSep } from '../../../shared/lib/page-path/normalize-path-sep'
import { getProxiedPluginState } from '../../build-context'
import { warnOnce } from '../../../shared/lib/utils/warn-once'

interface Options {
dev: boolean
appDir: string
isEdgeServer: boolean
useExperimentalReact: boolean
useServerActions: boolean
}

const PLUGIN_NAME = 'ClientEntryPlugin'
Expand Down Expand Up @@ -80,14 +79,14 @@ export class ClientReferenceEntryPlugin {
dev: boolean
appDir: string
isEdgeServer: boolean
useExperimentalReact: boolean
useServerActions: boolean
assetPrefix: string

constructor(options: Options) {
this.dev = options.dev
this.appDir = options.appDir
this.isEdgeServer = options.isEdgeServer
this.useExperimentalReact = options.useExperimentalReact
this.useServerActions = options.useServerActions
this.assetPrefix = !this.dev && !this.isEdgeServer ? '../' : ''
}

Expand Down Expand Up @@ -153,15 +152,17 @@ export class ClientReferenceEntryPlugin {
})
})

compiler.hooks.make.tap(PLUGIN_NAME, (compilation) => {
compilation.hooks.processAssets.tap(
{
name: PLUGIN_NAME,
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH,
},
(assets) => this.createAsset(compilation, assets)
)
})
if (this.useServerActions) {
compiler.hooks.make.tap(PLUGIN_NAME, (compilation) => {
compilation.hooks.processAssets.tap(
{
name: PLUGIN_NAME,
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH,
},
(assets) => this.createActionAssets(compilation, assets)
)
})
}
}

async createClientEntries(compiler: webpack.Compiler, compilation: any) {
Expand Down Expand Up @@ -241,20 +242,23 @@ export class ClientReferenceEntryPlugin {
)

if (actionEntryImports.size > 0) {
if (!this.useExperimentalReact) {
warnOnce(
'\nServer Actions require `experimental.experimentalReact` option to be enabled in your Next.js config.\n'
if (!this.useServerActions) {
compilation.errors.push(
new Error(
'Server Actions require `experimental.serverActions` option to be enabled in your Next.js config.'
)
)
} else {
addActionEntryList.push(
this.injectActionEntry({
compiler,
compilation,
actions: actionEntryImports,
entryName: name,
bundlePath: name,
})
)
}
addActionEntryList.push(
this.injectActionEntry({
compiler,
compilation,
actions: actionEntryImports,
entryName: name,
bundlePath: name,
})
)
}
})

Expand Down Expand Up @@ -780,7 +784,7 @@ export class ClientReferenceEntryPlugin {
})
}

createAsset(
createActionAssets(
compilation: webpack.Compilation,
assets: webpack.Compilation['assets']
) {
Expand Down
6 changes: 6 additions & 0 deletions packages/next/src/server/app-render/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export async function handleAction({
req.method === 'POST'

if (isFetchAction || isFormAction || isMultipartAction) {
if (!serverActionsManifest) {
throw new Error(
'Server Actions require `experimental.serverActions` option to be enabled in your Next.js config.'
)
}

let bound = []

const workerName = 'app' + pathname
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const configSchema = {
appDir: {
type: 'boolean',
},
experimentalReact: {
serverActions: {
type: 'boolean',
},
extensionAlias: {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export interface ExperimentalConfig {
/**
* Enable `react@experimental` channel for the `app` directory.
*/
experimentalReact?: boolean
serverActions?: boolean
}

export type ExportPathMap = {
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/server/lib/server-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const createWorker = (
ipcPort: number,
isNodeDebugging: boolean | 'brk' | undefined,
type: 'pages' | 'app',
useExperimentalReact?: boolean
useServerActions?: boolean
) => {
const { initialEnv } = require('@next/env') as typeof import('@next/env')
const { Worker } = require('next/dist/compiled/jest-worker')
Expand All @@ -91,7 +91,7 @@ export const createWorker = (
NODE_ENV: process.env.NODE_ENV,
...(type === 'app'
? {
__NEXT_PRIVATE_PREBUNDLED_REACT: useExperimentalReact
__NEXT_PRIVATE_PREBUNDLED_REACT: useServerActions
? 'experimental'
: 'next',
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export default class NextNodeServer extends BaseServer {
ipcPort,
options.isNodeDebugging,
'app',
this.nextConfig.experimental.experimentalReact
this.nextConfig.experimental.serverActions
)
}
this.renderWorkers.pages = createWorker(
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/actions/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
module.exports = {
experimental: {
appDir: true,
experimentalReact: true,
serverActions: true,
},
}