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

Remove experimental flag from serverActions.bodySizeLimit #57661

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions docs/02-app/02-api-reference/04-functions/server-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,14 @@ In both cases, the form is interactive before hydration occurs. Although Server

## Size Limitation

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.
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.
Copy link
Member Author

Choose a reason for hiding this comment

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

serverActionsBodySizeLimit ?? '1mb'


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'`.
However, you can configure this limit using the `serverActions.bodySizeLimit` option. It can take the number of bits or any string format supported by bits, for example `1000`, `'500kb'` or `'3mb'`.

```js filename="next.config.js"
module.exports = {
experimental: {
serverActions: {
bodySizeLimit: '2mb',
},
serverActions: {
bodySizeLimit: '2mb',
},
}
```
Expand Down
6 changes: 1 addition & 5 deletions examples/next-forms/next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverActions: true,
},
}
const nextConfig = {}

module.exports = nextConfig
6 changes: 1 addition & 5 deletions examples/with-fauna/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
const nextConfig = {
experimental: {
serverActions: true,
},
}
const nextConfig = {}

module.exports = nextConfig
6 changes: 1 addition & 5 deletions examples/with-stripe-typescript/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
serverActions: true,
},
}
module.exports = {}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ async fn wrap_edge_page(
// 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());
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub struct NextConfig {
pub dev_indicators: Option<DevIndicatorsConfig>,
pub output: Option<OutputType>,
pub analytics_id: Option<String>,
pub server_actions: Option<ServerActions>,

///
#[serde(rename = "_originalRedirects")]
Expand Down Expand Up @@ -442,7 +443,6 @@ pub struct ExperimentalConfig {
pub optimize_css: Option<serde_json::Value>,
pub next_script_workers: Option<bool>,
pub web_vitals_attribution: Option<Vec<String>>,
pub server_actions: Option<ServerActions>,
pub sri: Option<SubResourceIntegrity>,

// ---
Expand Down
3 changes: 1 addition & 2 deletions packages/next/src/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ export function getEdgeServerEntry(opts: {
middlewareConfig: Buffer.from(
JSON.stringify(opts.middlewareConfig || {})
).toString('base64'),
serverActionsBodySizeLimit:
opts.config.experimental.serverActions?.bodySizeLimit,
serverActionsBodySizeLimit: opts.config.serverActions?.bodySizeLimit,
}

return {
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/build/templates/edge-ssr-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { DocumentType } from '../../shared/lib/utils'
import type { BuildManifest } from '../../server/get-page-files'
import type { RequestData } from '../../server/web/types'
import type { NextConfigComplete } from '../../server/config-shared'
import type { SizeLimit } from '../../../types'

declare const incrementalCacheHandler: any
// OPTIONAL_IMPORT:incrementalCacheHandler
Expand All @@ -23,7 +24,7 @@ const error500Mod = null
declare const sriEnabled: boolean
declare const isServerComponent: boolean
declare const dev: boolean
declare const serverActionsBodySizeLimit: any
declare const serverActionsBodySizeLimit: SizeLimit
declare const nextConfig: NextConfigComplete
// INJECT:sriEnabled
// INJECT:isServerComponent
Expand Down
3 changes: 1 addition & 2 deletions packages/next/src/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,7 @@ export async function exportAppImpl(
optimizeFonts: nextConfig.optimizeFonts as FontConfig,
largePageDataBytes: nextConfig.experimental.largePageDataBytes,
serverComponents: options.hasAppDir,
serverActionsBodySizeLimit:
nextConfig.experimental.serverActions?.bodySizeLimit,
serverActionsBodySizeLimit: nextConfig.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 @@ -41,6 +41,7 @@ const supportedTurbopackNextConfigOptions = [
'amp',
'devIndicators',
'analyticsId',
'serverActions',

// Options that are ignored as they don't affect Turbopack
'webpack',
Expand Down Expand Up @@ -78,7 +79,6 @@ const supportedTurbopackNextConfigOptions = [
'experimental.logging.fullUrl',
'experimental.scrollRestoration',
'experimental.forceSwcTransforms',
'experimental.serverActions.bodySizeLimit',
'experimental.memoryBasedWorkersCount',
'experimental.clientRouterFilterRedirects',
'experimental.webpackBuildWorker',
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/server/app-render/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ export async function handleAction({
const { ApiError } = require('../api-utils')
throw new ApiError(
413,
`Body exceeded ${serverActionsBodySizeLimit} limit.
To configure the body size limit for Server Actions, see: https://nextjs.org/docs/app/api-reference/server-actions#size-limitation`
`Body exceeded ${serverActionsBodySizeLimit} limit. ` +
'To configure the body size limit for Server Actions, see: https://nextjs.org/docs/app/api-reference/functions/server-actions#size-limitation'
)
}

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 @@ -2095,7 +2095,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
isRevalidate: isSSG,
originalPathname: components.ComponentMod.originalPathname,
serverActionsBodySizeLimit:
this.nextConfig.experimental.serverActions?.bodySizeLimit,
this.nextConfig.serverActions?.bodySizeLimit,
}
: {}),
isDataReq,
Expand Down
14 changes: 7 additions & 7 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,6 @@ export interface ExperimentalConfig {
*/
taint?: boolean

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

/**
* enables the minification of server code.
*/
Expand Down Expand Up @@ -672,6 +665,13 @@ export interface NextConfig extends Record<string, any> {
}
}

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

/**
* Enable experimental features. Note that all experimental features are subject to breaking changes in the future.
*/
Expand Down
10 changes: 3 additions & 7 deletions packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,11 @@ function assignDefaults(
result.output = 'standalone'
}

if (
typeof result.experimental?.serverActions?.bodySizeLimit !== 'undefined'
) {
const value = parseInt(
result.experimental.serverActions?.bodySizeLimit.toString()
)
if (typeof result.serverActions?.bodySizeLimit !== 'undefined') {
const value = parseInt(result.serverActions?.bodySizeLimit.toString())
if (isNaN(value) || value < 1) {
throw new Error(
'Server Actions Size Limit must be a valid number or filesize format lager than 1MB: https://nextjs.org/docs/app/api-reference/server-actions#size-limitation'
'Server Actions Size Limit must be a valid number or filesize format lager than 1mb: https://nextjs.org/docs/app/api-reference/functions/server-actions#size-limitation'
)
}
}
Expand Down
18 changes: 5 additions & 13 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 @@ -2,7 +2,7 @@ import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils'

const CONFIG_ERROR =
'Server Actions Size Limit must be a valid number or filesize format lager than 1MB'
'Server Actions Size Limit must be a valid number or filesize format lager than 1mb'

createNextDescribe(
'app-dir action size limit invalid config',
Expand All @@ -26,9 +26,7 @@ createNextDescribe(
'next.config.js',
`
module.exports = {
experimental: {
serverActions: { bodySizeLimit: -3000 }
},
serverActions: { bodySizeLimit: -3000 }
}
`
)
Expand All @@ -44,9 +42,7 @@ createNextDescribe(
'next.config.js',
`
module.exports = {
experimental: {
serverActions: { bodySizeLimit: 'testmb' }
},
serverActions: { bodySizeLimit: 'testmb' }
}
`
)
Expand All @@ -62,9 +58,7 @@ createNextDescribe(
'next.config.js',
`
module.exports = {
experimental: {
serverActions: { bodySizeLimit: '-3000mb' }
},
serverActions: { bodySizeLimit: '-3000mb' }
}
`
)
Expand All @@ -81,9 +75,7 @@ createNextDescribe(
'next.config.js',
`
module.exports = {
experimental: {
serverActions: { bodySizeLimit: '1.5mb' }
},
serverActions: { bodySizeLimit: '1.5mb' }
}
`
)
Expand Down