Unverified Commit 772f3e75 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Add experimental React related warning (#47986)

For now, this isn't a strong requirement as normal `fetch` requests will
still work with `react@next`. But in the future, form related props e.g.
`action=` and `formAction=` requires the experimental build.

Fixes NEXT-954.
parent 9c0e5208
...@@ -2248,6 +2248,7 @@ export default async function getBaseWebpackConfig( ...@@ -2248,6 +2248,7 @@ export default async function getBaseWebpackConfig(
appDir, appDir,
dev, dev,
isEdgeServer, isEdgeServer,
useExperimentalReact,
})), })),
hasAppDir && hasAppDir &&
!isClient && !isClient &&
......
...@@ -32,11 +32,13 @@ import { ...@@ -32,11 +32,13 @@ import {
import { traverseModules, forEachEntryModule } from '../utils' import { traverseModules, forEachEntryModule } from '../utils'
import { normalizePathSep } from '../../../shared/lib/page-path/normalize-path-sep' import { normalizePathSep } from '../../../shared/lib/page-path/normalize-path-sep'
import { getProxiedPluginState } from '../../build-context' import { getProxiedPluginState } from '../../build-context'
import { warnOnce } from '../../../shared/lib/utils/warn-once'
interface Options { interface Options {
dev: boolean dev: boolean
appDir: string appDir: string
isEdgeServer: boolean isEdgeServer: boolean
useExperimentalReact: boolean
} }
const PLUGIN_NAME = 'ClientEntryPlugin' const PLUGIN_NAME = 'ClientEntryPlugin'
...@@ -75,11 +77,13 @@ export class ClientReferenceEntryPlugin { ...@@ -75,11 +77,13 @@ export class ClientReferenceEntryPlugin {
dev: boolean dev: boolean
appDir: string appDir: string
isEdgeServer: boolean isEdgeServer: boolean
useExperimentalReact: boolean
constructor(options: Options) { constructor(options: Options) {
this.dev = options.dev this.dev = options.dev
this.appDir = options.appDir this.appDir = options.appDir
this.isEdgeServer = options.isEdgeServer this.isEdgeServer = options.isEdgeServer
this.useExperimentalReact = options.useExperimentalReact
} }
apply(compiler: webpack.Compiler) { apply(compiler: webpack.Compiler) {
...@@ -241,6 +245,11 @@ export class ClientReferenceEntryPlugin { ...@@ -241,6 +245,11 @@ export class ClientReferenceEntryPlugin {
} }
if (actionEntryImports.size > 0) { 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( addActionEntryList.push(
this.injectActionEntry({ this.injectActionEntry({
compiler, compiler,
......
...@@ -14,15 +14,15 @@ export default function Form() { ...@@ -14,15 +14,15 @@ export default function Form() {
return ( return (
<> <>
<hr /> <hr />
<form action="" method="POST"> <form method="POST" action="">
<input type="text" name="name" id="name" required />
<input type="text" name="$$id" value={action.$$id} hidden readOnly /> <input type="text" name="$$id" value={action.$$id} hidden readOnly />
<input type="text" name="name" id="name" required />
<button type="submit" id="submit"> <button type="submit" id="submit">
Submit Submit
</button> </button>
</form> </form>
<hr /> <hr />
<form action="" method="POST"> <form method="POST" action="">
<input type="text" name="$$id" value={nowhere.$$id} hidden readOnly /> <input type="text" name="$$id" value={nowhere.$$id} hidden readOnly />
<button type="submit" id="nowhere"> <button type="submit" id="nowhere">
Go nowhere Go nowhere
......
/** @type {import('next').NextConfig} */
module.exports = { module.exports = {
experimental: { experimental: {
appDir: true, appDir: true,
experimentalReact: true,
}, },
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment