-
Notifications
You must be signed in to change notification settings - Fork 437
Adding support for Next 16 #2405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2405 +/- ##
==========================================
+ Coverage 88.76% 90.04% +1.27%
==========================================
Files 39 40 +1
Lines 4486 4529 +43
Branches 887 918 +31
==========================================
+ Hits 3982 4078 +96
+ Misses 501 445 -56
- Partials 3 6 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/server/next-compat.test.ts
Outdated
|
|
||
| import { toNextRequest, toNextResponse } from "./next-compat.js"; | ||
|
|
||
| describe("next-compact", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename "next-compact" to "next-compat"
| describe("next-compact", () => { | |
| describe("next-compat", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I have updated it in this commit a716c40
| /** | ||
| * Normalize a Request or NextRequest to a NextRequest instance. | ||
| * Ensures consistent behavior across Next.js 15 (Edge) and 16 (Node Proxy). | ||
| * @internal | ||
| */ | ||
| export function toNextRequest(input: Request | NextRequest): NextRequest { | ||
| if (input instanceof NextRequest) { | ||
| return input; | ||
| } | ||
|
|
||
| return new NextRequest(input.url, { | ||
| method: input.method, | ||
| headers: input.headers, | ||
| body: input.body as any, | ||
| duplex: (input as any).duplex ?? "half" | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to consider cloning input request body before transforming? Just a suggestion, open to comments on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason ? We are not writing into the original input object, we are just reading from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a TODO here 6575ee2
✅ Next.js 16 Support (Node Proxy Compatibility)
This PR adds full compatibility for both Next 15 (Edge middleware) and Next 16 (Node proxy) runtimes, without requiring any app-level code changes.
🔧 Changes
Request normalization:
Added internal
toNextRequest()helper to safely convert a plainRequest(as used in Next 16 proxy) to aNextRequest.Used in:
middleware()getSession()updateSession()getAccessTokenForConnection()createFetcher()Response normalization:
Introduced internal
toNextResponse()helper for consistent cookie and header handling when a plainResponseis used.Backward-compatibility:
All existing examples and apps continue to work.
Developers only need to:
middleware.ts→proxy.tsmiddleware→proxyEdge vs Node behavior:
Next 15 still runs middleware on Edge.
Next 16 runs proxy in Node runtime (middleware remains deprecated but supported under
experimental.nodeMiddleware).