Calling serverFn with large data results in error
Which project does this relate to?
Start
Describe the bug
Depending on the size of the array, I am observing either Access failed - CORS Error or 431 Header Too Large.
I tried wrapping with useServerFn - but I get same results.
This issue may be due to a bad configuration, bad code on my part, or legit bug.
Your Example Website or App
https://github.com/uninstallit/tanstart-large-data
Steps to Reproduce the Bug or Issue
- In the
useLargeDataHook>generateLoremIpsumData> set count to 100, then refresh and see logs. - In the
useLargeDataHook>generateLoremIpsumData> set count to 3000, then refresh, and see logs again.
Expected behavior
As a user, I expect at minimum a more helpful error message.
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome
- Version: Version 135.0.7049.85 (Official Build) (arm64)
Additional context
No response
Hey, were you able to resolve this issue? I am currently experiencing something similar. The server function is called with a large body but then the request url in the headers grows very large as well. So I end up getting a 431 HTTP Error when the request data grows.
@dannywamuya No I did not.
@uninstallit Hey, I actually solved this. My mistake was sending a large payload in GET server functions. You should use POST if your payload is big.
@dannywamuya Oh nice, I did not think of that. In my code above, I didn't specify the method - and I bet it defaults to a GET.
yes the default is GET. https://tanstack.com/start/latest/docs/framework/react/server-functions#available-options
@schiller-manuel Just one opinionated comment/suggestion. Since, I used a mutation in the code example - should the serverFn default to a POST instead when its called from a mutation.
the serverFn cannot be aware of its caller unfortunately.