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

Add experimental React related warning #47986

Merged
merged 4 commits into from Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: 3 additions & 3 deletions test/e2e/app-dir/actions/app/server/form.js
Expand Up @@ -14,15 +14,15 @@ export default function Form() {
return (
<>
<hr />
<form action="" method="POST">
<input type="text" name="name" id="name" required />
<form method="POST" action="">
<input type="text" name="$$id" value={action.$$id} hidden readOnly />
<input type="text" name="name" id="name" required />
<button type="submit" id="submit">
Submit
</button>
</form>
<hr />
<form action="" method="POST">
<form method="POST" action="">
<input type="text" name="$$id" value={nowhere.$$id} hidden readOnly />
<button type="submit" id="nowhere">
Go nowhere
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,
},
}