Skip to content

Conversation

@nandan-bhat
Copy link
Contributor

✅ 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 plain Request (as used in Next 16 proxy) to a NextRequest.
    Used in:

    • middleware()
    • getSession()
    • updateSession()
    • getAccessTokenForConnection()
    • createFetcher()
  • Response normalization:
    Introduced internal toNextResponse() helper for consistent cookie and header handling when a plain Response is used.

  • Backward-compatibility:
    All existing examples and apps continue to work.
    Developers only need to:

    • Rename middleware.tsproxy.ts
    • Rename the exported function middlewareproxy
  • Edge 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).

@nandan-bhat nandan-bhat requested a review from a team as a code owner November 7, 2025 08:07
@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.04%. Comparing base (b44aa97) to head (6575ee2).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


import { toNextRequest, toNextResponse } from "./next-compat.js";

describe("next-compact", () => {
Copy link
Contributor

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"

Suggested change
describe("next-compact", () => {
describe("next-compat", () => {

Copy link
Contributor Author

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

Comment on lines 3 to 19
/**
* 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"
});
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@nandan-bhat nandan-bhat Nov 10, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants