Skip to content

update proxy docs to use NextProxy type#90647

Merged
icyJoseph merged 5 commits intovercel:canaryfrom
clicktodev:patch-1
Mar 4, 2026
Merged

update proxy docs to use NextProxy type#90647
icyJoseph merged 5 commits intovercel:canaryfrom
clicktodev:patch-1

Conversation

@clicktodev
Copy link
Contributor

@clicktodev clicktodev commented Feb 27, 2026

What?

Updated all proxy code examples in the API reference to use the NextProxy typed arrow function pattern, consistent with the convention used in src/proxy.ts.

Why?

The proxy function is typed as NextProxy so parameters are inferred from the type, removing the need for explicit NextRequest imports.

How?

Updated all proxy code examples in the API reference to use the NextProxy typed arrow function pattern, consistent with the convention used in src/proxy.ts.

@nextjs-bot nextjs-bot added the Documentation Related to Next.js' official documentation. label Feb 27, 2026
@nextjs-bot
Copy link
Collaborator

nextjs-bot commented Feb 27, 2026

Allow CI Workflow Run

  • approve CI run for commit: 3f7a155

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Copy link
Member

@icyJoseph icyJoseph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! NextProxy I agree, we need to document this.

However, converting every single example to use NextProxy + arrow functions introduces a lot of stylistic churn without improving clarity. In fact, it makes most examples less clear, users lose sight of what request actually is (NextRequest, which extends Request), and the arrow function conversion in JS examples has zero benefit.

A better approach would be to:

  1. Keep the existing examples as-is explicit request: NextRequest is more pedagogical for reference docs, and it also makes it easier to introduce event argument, I'd argue anyway.
  2. Add a dedicated example snippet (e.g., in the Params section or near the top, or right at the end of the Examples section) that shows the NextProxy typed pattern, explaining that it infers parameter types (NextRequest, NextFetchEvent) so you don't need to import them individually. This is where showing both styles side-by-side would be valuable, it teaches users the shorthand and what the actual parameter types are.

That way the type gets proper visibility without losing explicitness everywhere else.

@clicktodev clicktodev requested a review from icyJoseph March 3, 2026 11:50
@clicktodev
Copy link
Contributor Author

clicktodev commented Mar 3, 2026

a bit unrelated but the vercel cron docs can benefit from the same improvement by using the VercelApiHandler type instead of manually typing the params

image

export const proxy: NextProxy = (request, event) => {
event.waitUntil(Promise.resolve())
return Response.json({ pathname: request.nextUrl.pathname })
}
Copy link
Member

@icyJoseph icyJoseph Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anyone else arriving here, we did have NextMiddleware too, a bit too late 🥲

@icyJoseph icyJoseph merged commit 11c906a into vercel:canary Mar 4, 2026
62 checks passed
@clicktodev clicktodev deleted the patch-1 branch March 4, 2026 12:33
@clicktodev
Copy link
Contributor Author

is there a similar type for next route handlers so we don't have to type the params manually?

sokra pushed a commit that referenced this pull request Mar 6, 2026
### What?
Updated all proxy code examples in the API reference to use the
`NextProxy` typed arrow function pattern, consistent with the convention
used in `src/proxy.ts`.

### Why?
The proxy function is typed as `NextProxy` so parameters are inferred
from the type, removing the need for explicit `NextRequest` imports.

### How?
Updated all proxy code examples in the API reference to use the
`NextProxy` typed arrow function pattern, consistent with the convention
used in `src/proxy.ts`.

---------

Co-authored-by: Joseph <sephxd1234@gmail.com>
Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Related to Next.js' official documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants