Skip to content

fix(config): reject invalid action body limits - #2807

Open
Boyeep wants to merge 3 commits into
cloudflare:mainfrom
Boyeep:fix/action-body-limit-validation
Open

fix(config): reject invalid action body limits#2807
Boyeep wants to merge 3 commits into
cloudflare:mainfrom
Boyeep:fix/action-body-limit-validation

Conversation

@Boyeep

@Boyeep Boyeep commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • reject genuinely invalid experimental.serverActions.bodySizeLimit values during config resolution instead of silently substituting 1 MB
  • use Next.js's canonical error and documentation link
  • mirror Next.js's vendored bytes.parse() grammar and fallback exactly, including explicit + signs and its unusual parseInt fallback
  • preserve the original configured label used by runtime body-limit errors

User impact and reproduction

With:

export default {
  experimental: {
    serverActions: { bodySizeLimit: "testmb" },
  },
}

Next.js refuses to start or build. Vinext previously warned, silently changed the value to 1 MB, and continued. That hides configuration mistakes until a Server Action later fails at a limit the developer never selected. Negative strings behaved the same way, negative numbers used a vinext-specific error, and wrong-type values were treated as omitted.

Strict parity also matters for accepted strings. Next's vendored parser accepts "+2mb", but for strings outside its complete filesize grammar it falls back to parseInt(value, 10): for example, "2wat" is 2 bytes, "1e3" is 1 byte, and "1mb " is 1 byte. This PR preserves those surprising but authoritative semantics instead of inventing stricter validation.

Expected Next.js behavior

Next validates bodySizeLimit during config resolution. Numbers pass through directly; strings go through its vendored bytes.parse(); null, NaN, and results below one byte throw the canonical config error.

Execution paths

resolveNextConfig is the shared configuration boundary for:

  • App Router development, production, and prerendering
  • CLI and Cloudflare Worker builds
  • Pages Router development/production config loading

Server Actions are an App Router feature; Pages paths do not consume the runtime action limit, but they share the same config validation just as Next validates the option globally.

Tests and verification

Tests were added first. The fallback-parity test failed against the previous implementation ("1mb " returned 1 MiB rather than 1 byte), then passed after the parser change.

Coverage includes malformed/negative strings, zero/NaN, wrong types, omitted defaults, valid numeric and unit values, +2mb, and fallback cases "1mb ", " 1mb", tab-separated units, "2wat", "1e3", and "1.5".

  • pnpm test tests/next-config.test.ts — 223 passed
  • pnpm exec vp check packages/vinext/src/config/next-config.ts tests/next-config.test.ts — passed
  • pnpm run build — passed (only the repository's expected virtual-module external warnings)

Self-review

Automated review correctly identified missing explicit-positive-sign support; commit debb4e1a added it. The final review then found a broader issue: the hand-written parser was still stricter than Next's vendored parser. Commit 004f4aa0 replaces it with the same grammar, unit multipliers, flooring, and parseInt fallback while keeping valid error cases strict.

I also tested removing the apparent duplicate type guard in config resolution. It is retained because it narrows the original value before preserving the runtime error label, avoiding an unsafe cast or object stringification.

@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vinext/cloudflare@2807
npm i https://pkg.pr.new/create-vinext-app@2807
npm i https://pkg.pr.new/@vinext/types@2807
npm i https://pkg.pr.new/vinext@2807

commit: 004f4aa

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared 004f4aa against base dfc979c using alternating same-runner rounds. Next.js was unchanged and skipped.

0 improved · 0 regressed · 6 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 134.6 KB 134.6 KB ⚫ +0.0%
Client entry size (gzip) vinext 122.2 KB 122.2 KB ⚫ +0.0%
Dev server cold start vinext 3.00 s 2.98 s ⚫ -0.9%
Production build time vinext 3.26 s 3.27 s ⚫ +0.2%
RSC entry closure size (gzip) vinext 113.8 KB 113.8 KB ⚫ -0.0%
Server bundle size (gzip) vinext 191.3 KB 191.3 KB ⚫ -0.0%

View detailed results and traces

🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant