router icon indicating copy to clipboard operation
router copied to clipboard

Calling serverFn with large data results in error

Open uninstallit opened this issue 9 months ago • 1 comments

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

  1. In the useLargeDataHook > generateLoremIpsumData > set count to 100, then refresh and see logs.
  2. 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

uninstallit avatar Apr 10 '25 10:04 uninstallit

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 avatar Jun 17 '25 19:06 dannywamuya

@dannywamuya No I did not.

uninstallit avatar Jun 24 '25 15:06 uninstallit

@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 avatar Jun 24 '25 15:06 dannywamuya

@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.

uninstallit avatar Jun 25 '25 09:06 uninstallit

yes the default is GET. https://tanstack.com/start/latest/docs/framework/react/server-functions#available-options

schiller-manuel avatar Jun 25 '25 21:06 schiller-manuel

@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.

uninstallit avatar Jun 26 '25 10:06 uninstallit

the serverFn cannot be aware of its caller unfortunately.

schiller-manuel avatar Jun 26 '25 16:06 schiller-manuel