Skip to content

Commit

Permalink
Move serverActionsBodySizeLimit to serverActions.bodySizeLimit (#57433)
Browse files Browse the repository at this point in the history
Scope all `serverActions` config in one group "serverActions" to make it
more semantics

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
huozhi and kodiakhq[bot] authored Oct 26, 2023
1 parent b3e5392 commit 07483d4
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 27 deletions.
6 changes: 4 additions & 2 deletions docs/02-app/02-api-reference/04-functions/server-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ In both cases, the form is interactive before hydration occurs. Although Server

By default, the maximum size of the request body sent to a Server Action is 1MB, to prevent the consumption of excessive server resources in parsing large amounts of data.

However, you can configure this limit using the `serverActionsBodySizeLimit` option. It can take the number of bytes or any string format supported by bytes, for example `1000`, `'500kb'` or `'3mb'`.
However, you can configure this limit using the `serverActions.bodySizeLimit` option. It can take the number of bytes or any string format supported by bytes, for example `1000`, `'500kb'` or `'3mb'`.

```js filename="next.config.js"
module.exports = {
experimental: {
serverActionsBodySizeLimit: '2mb',
serverActions: {
bodySizeLimit: '2mb',
},
},
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,14 @@ async fn wrap_edge_page(
// TODO(timneutkens): remove this
let is_server_component = true;

let server_actions_body_size_limit = &next_config.experimental.server_actions_body_size_limit;
// let server_actions_body_size_limit =
// &next_config.experimental.server_actions.body_size_limit;
let server_actions_body_size_limit = next_config
.experimental
.server_actions
.as_ref()
.and_then(|sa| sa.body_size_limit.as_ref());

let sri_enabled = !dev
&& next_config
.experimental
Expand All @@ -177,7 +184,7 @@ async fn wrap_edge_page(
"nextConfig" => serde_json::to_string(next_config)?,
"isServerComponent" => serde_json::Value::Bool(is_server_component).to_string(),
"dev" => serde_json::Value::Bool(dev).to_string(),
"serverActionsBodySizeLimit" => serde_json::to_string(server_actions_body_size_limit)?,
"serverActionsBodySizeLimit" => serde_json::to_string(&server_actions_body_size_limit)?
},
indexmap! {
"incrementalCacheHandler" => None,
Expand Down
13 changes: 8 additions & 5 deletions packages/next-swc/crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,7 @@ pub struct ExperimentalConfig {
pub optimize_css: Option<serde_json::Value>,
pub next_script_workers: Option<bool>,
pub web_vitals_attribution: Option<Vec<String>>,
/// Enables server actions. Using this feature will enable the
/// `react@experimental` for the `app` directory. @see https://nextjs.org/docs/app/api-reference/functions/server-actions
server_actions: Option<bool>,
/// Allows adjusting body parser size limit for server actions.
pub server_actions_body_size_limit: Option<SizeLimit>,
pub server_actions: Option<ServerActions>,
pub sri: Option<SubResourceIntegrity>,

// ---
Expand Down Expand Up @@ -515,6 +511,13 @@ pub struct SubResourceIntegrity {
pub algorithm: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
#[serde(rename_all = "camelCase")]
pub struct ServerActions {
/// Allows adjusting body parser size limit for server actions.
pub body_size_limit: Option<SizeLimit>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
#[serde(untagged)]
pub enum SizeLimit {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export function getEdgeServerEntry(opts: {
JSON.stringify(opts.middlewareConfig || {})
).toString('base64'),
serverActionsBodySizeLimit:
opts.config.experimental.serverActionsBodySizeLimit,
opts.config.experimental.serverActions?.bodySizeLimit,
}

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export async function exportAppImpl(
largePageDataBytes: nextConfig.experimental.largePageDataBytes,
serverComponents: options.hasAppDir,
serverActionsBodySizeLimit:
nextConfig.experimental.serverActionsBodySizeLimit,
nextConfig.experimental.serverActions?.bodySizeLimit,
nextFontManifest: require(join(
distDir,
'server',
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/lib/turbopack-warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const supportedTurbopackNextConfigOptions = [
'experimental.logging.fullUrl',
'experimental.scrollRestoration',
'experimental.forceSwcTransforms',
'experimental.serverActionsBodySizeLimit',
'experimental.serverActions.bodySizeLimit',
'experimental.memoryBasedWorkersCount',
'experimental.clientRouterFilterRedirects',
'experimental.webpackBuildWorker',
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
isRevalidate: isSSG,
originalPathname: components.ComponentMod.originalPathname,
serverActionsBodySizeLimit:
this.nextConfig.experimental.serverActionsBodySizeLimit,
this.nextConfig.experimental.serverActions?.bodySizeLimit,
}
: {}),
isDataReq,
Expand Down
10 changes: 6 additions & 4 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,12 @@ export interface ExperimentalConfig {
*/
taint?: boolean

/**
* Allows adjusting body parser size limit for server actions.
*/
serverActionsBodySizeLimit?: SizeLimit
serverActions?: {
/**
* Allows adjusting body parser size limit for server actions.
*/
bodySizeLimit?: SizeLimit
}

/**
* enables the minification of server code.
Expand Down
6 changes: 4 additions & 2 deletions packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,11 @@ function assignDefaults(
result.output = 'standalone'
}

if (typeof result.experimental?.serverActionsBodySizeLimit !== 'undefined') {
if (
typeof result.experimental?.serverActions?.bodySizeLimit !== 'undefined'
) {
const value = parseInt(
result.experimental.serverActionsBodySizeLimit.toString()
result.experimental.serverActions?.bodySizeLimit.toString()
)
if (isNaN(value) || value < 1) {
throw new Error(
Expand Down
16 changes: 8 additions & 8 deletions test/e2e/app-dir/actions/app-action-size-limit-invalid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ createNextDescribe(
return
}

it('should error if serverActionsBodySizeLimit config is a negative number', async function () {
it('should error if serverActions.bodySizeLimit config is a negative number', async function () {
await next.patchFile(
'next.config.js',
`
module.exports = {
experimental: {
serverActionsBodySizeLimit: -3000,
serverActions: { bodySizeLimit: -3000 }
},
}
`
Expand All @@ -39,13 +39,13 @@ createNextDescribe(
expect(next.cliOutput).toContain(CONFIG_ERROR)
})

it('should error if serverActionsBodySizeLimit config is invalid', async function () {
it('should error if serverActions.bodySizeLimit config is invalid', async function () {
await next.patchFile(
'next.config.js',
`
module.exports = {
experimental: {
serverActionsBodySizeLimit: 'testmb',
serverActions: { bodySizeLimit: 'testmb' }
},
}
`
Expand All @@ -57,13 +57,13 @@ createNextDescribe(
expect(next.cliOutput).toContain(CONFIG_ERROR)
})

it('should error if serverActionsBodySizeLimit config is a negative size', async function () {
it('should error if serverActions.bodySizeLimit config is a negative size', async function () {
await next.patchFile(
'next.config.js',
`
module.exports = {
experimental: {
serverActionsBodySizeLimit: '-3000mb',
serverActions: { bodySizeLimit: '-3000mb' }
},
}
`
Expand All @@ -76,13 +76,13 @@ createNextDescribe(
})

if (!isNextDeploy) {
it('should respect the size set in serverActionsBodySizeLimit', async function () {
it('should respect the size set in serverActions.bodySizeLimit', async function () {
await next.patchFile(
'next.config.js',
`
module.exports = {
experimental: {
serverActionsBodySizeLimit: '1.5mb',
serverActions: { bodySizeLimit: '1.5mb' }
},
}
`
Expand Down

1 comment on commit 07483d4

@ijjk
Copy link
Member

@ijjk ijjk commented on 07483d4 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stats from current release

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary v13.5.6 vercel/next.js canary Change
buildDuration 10.4s 11.3s ⚠️ +957ms
buildDurationCached 6.4s 6.2s N/A
nodeModulesSize 172 MB 175 MB ⚠️ +2.64 MB
nextStartRea..uration (ms) 516ms 398ms N/A
Client Bundles (main, webpack) Overall increase ⚠️
vercel/next.js canary v13.5.6 vercel/next.js canary Change
199-HASH.js gzip 27.5 kB N/A N/A
3f784ff6-HASH.js gzip 50.9 kB N/A N/A
99.HASH.js gzip 182 B 182 B
framework-HASH.js gzip 45.3 kB 45.5 kB ⚠️ +223 B
main-app-HASH.js gzip 253 B 252 B N/A
main-HASH.js gzip 32.9 kB 35.4 kB ⚠️ +2.49 kB
webpack-HASH.js gzip 1.75 kB 1.75 kB N/A
3c4a14c2-HASH.js gzip N/A 53.2 kB N/A
513-HASH.js gzip N/A 32.4 kB N/A
Overall change 78.4 kB 81.1 kB ⚠️ +2.71 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary v13.5.6 vercel/next.js canary Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary v13.5.6 vercel/next.js canary Change
_app-HASH.js gzip 206 B 205 B N/A
_error-HASH.js gzip 182 B 180 B N/A
amp-HASH.js gzip 506 B 505 B N/A
css-HASH.js gzip 322 B 323 B N/A
dynamic-HASH.js gzip 2.57 kB 2.59 kB N/A
edge-ssr-HASH.js gzip 260 B 259 B N/A
head-HASH.js gzip 350 B 350 B
hooks-HASH.js gzip 369 B 369 B
image-HASH.js gzip 4.35 kB 4.38 kB N/A
index-HASH.js gzip 256 B 256 B
link-HASH.js gzip 2.64 kB 2.67 kB N/A
routerDirect..HASH.js gzip 312 B 318 B N/A
script-HASH.js gzip 385 B 384 B N/A
withRouter-HASH.js gzip 307 B 319 B N/A
1afbb74e6ecf..834.css gzip 106 B 106 B
Overall change 1.08 kB 1.08 kB
Client Build Manifests
vercel/next.js canary v13.5.6 vercel/next.js canary Change
_buildManifest.js gzip 485 B 482 B N/A
Overall change 0 B 0 B
Rendered Page Sizes
vercel/next.js canary v13.5.6 vercel/next.js canary Change
index.html gzip 527 B 529 B N/A
link.html gzip 541 B 542 B N/A
withRouter.html gzip 524 B 525 B N/A
Overall change 0 B 0 B
Edge SSR bundle Size Overall increase ⚠️
vercel/next.js canary v13.5.6 vercel/next.js canary Change
edge-ssr.js gzip 93.9 kB 96 kB ⚠️ +2.11 kB
page.js gzip 152 kB 140 kB N/A
Overall change 93.9 kB 96 kB ⚠️ +2.11 kB
Middleware size Overall increase ⚠️
vercel/next.js canary v13.5.6 vercel/next.js canary Change
middleware-b..fest.js gzip 624 B 620 B N/A
middleware-r..fest.js gzip 150 B 151 B N/A
middleware.js gzip 22.9 kB 25.6 kB ⚠️ +2.69 kB
edge-runtime..pack.js gzip 1.92 kB 1.92 kB
Overall change 24.8 kB 27.5 kB ⚠️ +2.69 kB
Diff details
Diff for page.js
failed to diff
Diff for middleware.js

Diff too large to display

Diff for edge-ssr.js

Diff too large to display

Diff for image-HASH.js
@@ -1,7 +1,7 @@
 (self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([
   [358],
   {
-    /***/ 1552: /***/ function (
+    /***/ 4070: /***/ function (
       __unused_webpack_module,
       __unused_webpack_exports,
       __webpack_require__
@@ -9,7 +9,7 @@
       (window.__NEXT_P = window.__NEXT_P || []).push([
         "/image",
         function () {
-          return __webpack_require__(528);
+          return __webpack_require__(5921);
         },
       ]);
       if (false) {
@@ -18,7 +18,7 @@
       /***/
     },
 
-    /***/ 4036: /***/ function (module, exports, __webpack_require__) {
+    /***/ 2155: /***/ function (module, exports, __webpack_require__) {
       "use strict";
       /* __next_internal_client_entry_do_not_use__  cjs */
       Object.defineProperty(exports, "__esModule", {
@@ -39,15 +39,15 @@
         __webpack_require__(422)
       );
       const _head = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(8777)
+        __webpack_require__(9561)
       );
-      const _getimgprops = __webpack_require__(2391);
-      const _imageconfig = __webpack_require__(1138);
-      const _imageconfigcontextsharedruntime = __webpack_require__(5615);
-      const _warnonce = __webpack_require__(7536);
-      const _routercontextsharedruntime = __webpack_require__(6174);
+      const _getimgprops = __webpack_require__(3787);
+      const _imageconfig = __webpack_require__(3767);
+      const _imageconfigcontextsharedruntime = __webpack_require__(8744);
+      const _warnonce = __webpack_require__(6908);
+      const _routercontextsharedruntime = __webpack_require__(937);
       const _imageloader = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(7512)
+        __webpack_require__(2534)
       );
       // This is replaced by webpack define plugin
       const configEnv = {
@@ -127,7 +127,7 @@
         });
       }
       function getDynamicProps(fetchPriority) {
-        const [majorStr, minorStr] = _react.version.split(".");
+        const [majorStr, minorStr] = _react.version.split(".", 2);
         const major = parseInt(majorStr, 10);
         const minor = parseInt(minorStr, 10);
         if (major > 18 || (major === 18 && minor >= 3)) {
@@ -372,7 +372,7 @@
       /***/
     },
 
-    /***/ 2391: /***/ function (
+    /***/ 3787: /***/ function (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -388,9 +388,9 @@
           return getImgProps;
         },
       });
-      const _warnonce = __webpack_require__(7536);
-      const _imageblursvg = __webpack_require__(9080);
-      const _imageconfig = __webpack_require__(1138);
+      const _warnonce = __webpack_require__(6908);
+      const _imageblursvg = __webpack_require__(9317);
+      const _imageconfig = __webpack_require__(3767);
       const VALID_LOADING_VALUES =
         /* unused pure expression or super */ null && [
           "lazy",
@@ -759,7 +759,7 @@
       /***/
     },
 
-    /***/ 9080: /***/ function (__unused_webpack_module, exports) {
+    /***/ 9317: /***/ function (__unused_webpack_module, exports) {
       "use strict";
       /**
        * A shared function, used on both client and server, to generate a SVG blur placeholder.
@@ -814,7 +814,7 @@
       /***/
     },
 
-    /***/ 33: /***/ function (
+    /***/ 7196: /***/ function (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -841,11 +841,11 @@
         },
       });
       const _interop_require_default = __webpack_require__(1351);
-      const _getimgprops = __webpack_require__(2391);
-      const _warnonce = __webpack_require__(7536);
-      const _imagecomponent = __webpack_require__(4036);
+      const _getimgprops = __webpack_require__(3787);
+      const _warnonce = __webpack_require__(6908);
+      const _imagecomponent = __webpack_require__(2155);
       const _imageloader = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(7512)
+        __webpack_require__(2534)
       );
       const unstable_getImgProps = (imgProps) => {
         (0, _warnonce.warnOnce)(
@@ -877,7 +877,7 @@
       /***/
     },
 
-    /***/ 7512: /***/ function (__unused_webpack_module, exports) {
+    /***/ 2534: /***/ function (__unused_webpack_module, exports) {
       "use strict";
 
       Object.defineProperty(exports, "__esModule", {
@@ -912,7 +912,7 @@
       /***/
     },
 
-    /***/ 528: /***/ function (
+    /***/ 5921: /***/ function (
       __unused_webpack_module,
       __webpack_exports__,
       __webpack_require__
@@ -933,8 +933,8 @@
 
       // EXTERNAL MODULE: ./node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js
       var jsx_runtime = __webpack_require__(1527);
-      // EXTERNAL MODULE: ./node_modules/.pnpm/file+..+main-repo+packages+next+next-packed.tgz_react-dom@18.2.0_react@18.2.0/node_modules/next/image.js
-      var next_image = __webpack_require__(1577);
+      // EXTERNAL MODULE: ./node_modules/.pnpm/file+..+diff-repo+packages+next+next-packed.tgz_react-dom@18.2.0_react@18.2.0/node_modules/next/image.js
+      var next_image = __webpack_require__(73);
       var image_default = /*#__PURE__*/ __webpack_require__.n(next_image); // CONCATENATED MODULE: ./pages/nextjs.png
       /* harmony default export */ var nextjs = {
         src: "/_next/static/media/nextjs.cae0b805.png",
@@ -964,12 +964,12 @@
       /***/
     },
 
-    /***/ 1577: /***/ function (
+    /***/ 73: /***/ function (
       module,
       __unused_webpack_exports,
       __webpack_require__
     ) {
-      module.exports = __webpack_require__(33);
+      module.exports = __webpack_require__(7196);
 
       /***/
     },
@@ -980,7 +980,7 @@
       return __webpack_require__((__webpack_require__.s = moduleId));
     };
     /******/ __webpack_require__.O(0, [774, 888, 179], function () {
-      return __webpack_exec__(1552);
+      return __webpack_exec__(4070);
     });
     /******/ var __webpack_exports__ = __webpack_require__.O();
     /******/ _N_E = __webpack_exports__;
Diff for 199-HASH.js

Diff too large to display

Diff for 3f784ff6-HASH.js

Diff too large to display

Diff for main-HASH.js

Diff too large to display

Please sign in to comment.