Skip to content

Commit

Permalink
warn to use experimental react to enable actions
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Apr 5, 2023
1 parent 1fbbba6 commit 5190a4c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/next/src/build/webpack-config.ts
Expand Up @@ -2248,6 +2248,7 @@ export default async function getBaseWebpackConfig(
appDir,
dev,
isEdgeServer,
useExperimentalReact,
})),
hasAppDir &&
!isClient &&
Expand Down
Expand Up @@ -32,11 +32,13 @@ 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
}

const PLUGIN_NAME = 'ClientEntryPlugin'
Expand Down Expand Up @@ -75,11 +77,13 @@ export class ClientReferenceEntryPlugin {
dev: boolean
appDir: string
isEdgeServer: boolean
useExperimentalReact: boolean

constructor(options: Options) {
this.dev = options.dev
this.appDir = options.appDir
this.isEdgeServer = options.isEdgeServer
this.useExperimentalReact = options.useExperimentalReact
}

apply(compiler: webpack.Compiler) {
Expand Down Expand Up @@ -241,6 +245,11 @@ 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'
)
}
addActionEntryList.push(
this.injectActionEntry({
compiler,
Expand Down
6 changes: 2 additions & 4 deletions test/e2e/app-dir/actions/app/server/form.js
Expand Up @@ -14,16 +14,14 @@ export default function Form() {
return (
<>
<hr />
<form action="" method="POST">
<form method="POST" action={action}>
<input type="text" name="name" id="name" required />
<input type="text" name="$$id" value={action.$$id} hidden readOnly />
<button type="submit" id="submit">
Submit
</button>
</form>
<hr />
<form action="" method="POST">
<input type="text" name="$$id" value={nowhere.$$id} hidden readOnly />
<form method="POST" action={nowhere}>
<button type="submit" id="nowhere">
Go nowhere
</button>
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/app-dir/actions/next.config.js
@@ -1,5 +1,7 @@
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
appDir: true,
experimentalReact: true,
},
}

0 comments on commit 5190a4c

Please sign in to comment.