mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #443] fix: can't use next/headers in server action and route #99
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#99
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @bestyxie on GitHub (Mar 11, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/443
always caught an error: headers() can only be called from a Server Component, Route Handler, or Server Action. Make sure you're not calling it from a Client Component.
But I do use it in server action and route handler. now the only way I could use it is Server Component.
@Divkix commented on GitHub (Mar 11, 2026):
I checked the current App Router request path in main, and both route handlers and server actions are already executed under the same request headers/cookies context, so this is not an obvious framework bug from code inspection alone. Route handlers also already have compat coverage for next/headers.
What I don’t see yet is a minimal reproduction for headers() specifically inside a server action. Could you share a small repro repo or the exact server action / route handler code that fails, plus whether this happens in dev, build, or both? If you can provide that, we can confirm whether this is a real vinext bug or a usage-specific issue and add a regression test.
@ryanbuening commented on GitHub (Mar 11, 2026):
I might have a similar issue. Something in 0.0.27 caused issues with
next/headerswhere it loses the correctthisbinding during iteration. It results in "TypeError: Illegal invocation". I'm using the function below as a workaround:@Divkix commented on GitHub (Mar 12, 2026):
Thanks, I tracked down the
TypeError: Illegal invocationreport and that one is a real bug on our side.The issue was in the
next/headersshim: the lazy request-backedHeadersproxy was returningSymbol.iteratorunbound, so iterator-based usage likeArray.from(headers()),[...headers()], orObject.fromEntries(headers())could fail even thoughforEach()worked.I opened a fix here: https://github.com/cloudflare/vinext/pull/480
That PR also adds regression coverage for:
headers()access in the shimheaders()access in a real App Router route handlerSo the workaround of copying into a fresh
Headersobject should no longer be needed once that lands.Separately, this looks different from the original issue body (
headers() can only be called from a Server Component, Route Handler, or Server Action). I still can’t reproduce that specific failure on currentmain, and route handlers / server actions already run with the request headers context in code. If you’re still hitting that original error, please share a minimal repro or the exact route handler / server action code, and whether it happens in dev, build, or both@bestyxie commented on GitHub (Mar 13, 2026):
I upgraded the vinext version from 0.0.21 to 0.0.29, problem solved.