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(
appDir,
dev,
isEdgeServer,
useExperimentalReact,
})),
hasAppDir &&
!isClient &&
......
......@@ -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'
......@@ -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) {
......@@ -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,
......
......@@ -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
......
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
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