From 5d1f33f5c42a3ab2d88db16471cd108531d65f71 Mon Sep 17 00:00:00 2001 From: Luis Alvarez D Date: Mon, 28 Mar 2022 16:15:08 -0500 Subject: [PATCH] Add deprecated JSDoc comments for the previous middleware signature (#35448) Something I noticed while using Middleware is that the older and no longer working methods are still accessible for the `event` with autocompletion because of their types, and the way of knowing they're deprecated is by running the app and seeing the error message, this should improve that when coding in tools like VS Code. ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [x] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint` Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com> --- .../next/server/web/spec-extension/fetch-event.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/next/server/web/spec-extension/fetch-event.ts b/packages/next/server/web/spec-extension/fetch-event.ts index 4e1af9e28a1a08b..43374e9bd72f500 100644 --- a/packages/next/server/web/spec-extension/fetch-event.ts +++ b/packages/next/server/web/spec-extension/fetch-event.ts @@ -10,13 +10,22 @@ export class NextFetchEvent extends FetchEvent { this.sourcePage = params.page } - // @ts-ignore + /** + * @deprecated The `request` is now the first parameter and the API is now async. + * + * Read more: https://nextjs.org/docs/messages/middleware-new-signature + */ get request() { throw new DeprecationError({ page: this.sourcePage, }) } + /** + * @deprecated Using `respondWith` is no longer needed. + * + * Read more: https://nextjs.org/docs/messages/middleware-new-signature + */ respondWith() { throw new DeprecationError({ page: this.sourcePage,