Repository navigation
fix(next): prevent 1MB body limit error when uploading files - #15078
Closed
sohamingle wants to merge 5 commits into
Closed
sohamingle wants to merge 5 commits into
sohamingle wants to merge 5 commits into
Conversation
…ding Server Action body size limit ### What? Modifies the ServerFunctionsProvider to remove file data from formState before sending it to the server. ### Why? To avoid exceeding the 5MB body size limit for Server Actions, as file objects are not needed for form state validation. ### Changes - Updated the handling of formStateArgs to nullify the file value if it is an instance of File. No breaking changes introduced.
sohamingle
requested review from
AlessioGr,
JarrodMFlesch and
jacobsfletch
as code owners
January 3, 2026 20:13
r1tsuu
added a commit
that referenced
this pull request
Jan 12, 2026
Fixes #15073 Surprasses #15078 We use the `deepCopyObjectSimpleWithoutReactComponents` function to serialize data for the form state action. This PR adds a new option to `deepCopyObjectSimpleWithoutReactComponents` - `excludeFiles: boolean` and adds usage of it in places where we call the form state action to: * Avoid overhead of sending the file on every form state calculation when the collection has uploads enabled, since we don't actually use the file inside the form state action. * Fix the issue with client uploads when the file exceeds the platform limit.
Contributor
|
Thank you for working on a solution for this! Unfortunately, we made a confusing situation from earlier regressions which should all be fixed by the recently merged #15174. Closing this but we really appreciate taking your time on this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Strip file data from
formStatebefore sending it to thegetFormStateserver action to avoid exceeding Next.js Server Actions' 1MB body size limit.Why?
When uploading files larger than 1MB, the following error occurs:
This happens because:
formState.file.valueformStatetogetFormStatefor validation, field rendering, and permissions checkinggetFormStateis a Server Action, which has a default 1MB body size limit in Next.jsHow?
The fix strips the file value from
formStatebefore sending it to the server action:This is safe because:
buildFormStatehandles field validation, rendering, permissions, and document locking - none of which require the actual file binary(POST /api/[collection])with multipart form data, not through Server ActionsbuildFormState.ts, line 223-226, it preserves the file field from the incoming form state, so passingnulldoesn't break anythingVideo Demo
Before
Arc.2026-01-04.01-41-22.mp4
After
Arc.2026-01-04.01-41-58.mp4
How to test?
Error "Body exceeded 1mb limit"appears immediately when file is selectedFixes #15073