ai/rsc and middleware header size failing
Description
With ai/rsc the post requests go to the same route and the AIState is send as part of the server action form header. As a conversation grows long and there is a lot of metadata, this can make the headers quite large.
Since many apps like ours use middleware for critical functions like authentication, this causes errors. I believe as of next 14.1, server actions go through middleware by default and this is causing this to happen often:
[POST] [middleware: "src/middleware"] /plugin/chat reason=REQUEST_HEADER_TOO_LARGE, status=431, user_error=true
While I realize this error isn't specific to ai/rsc, the way the library works to wrap server actions with the AIState in each request causes this in our case. I assume many people will run into this problem.
I believe the fix is to add next-action to the missing header.
missing: [
{ type: 'header', key: 'next-router-prefetch' },
{ type: 'header', key: 'purpose', value: 'prefetch' },
{ type: 'header', key: 'next-action' },
],
We moved our implementation to the rsc library, which was a good amount of work but pushed a lot of logic to the server. But this caused us to have to revert before moving to production.
Should this directly be addressed in the docs or a code change?
Code example
No response
Additional context
We also use fairly large URLs to represent state and because next includes the router history in headers, the 2 add up to cause problems. Even when removing this we still ran into problems with large message history and metadata.