Skip to content

Commit 961a0f5

Browse files
docs: add pageExtensions note to Middleware and clarify default filename (#84045)
- Added a Note to the Middleware docs explaining that when `pageExtensions` are customized (e.g. `.page.ts`), the Middleware file should be named `middleware.page.ts` or `middleware.page.js`. - Updated wording so `middleware.ts/js` is described as the default filename, not a strict requirement. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? -Added a callout note to middleware.mdx stating that if pageExtensions is customized (e.g., .page.ts), the Middleware file should also match (middleware.page.ts/js). -Updated the language from “must” → “default is” for filename clarity. ### Why? -Developers customizing pageExtensions were misled by the existing docs, which implied middleware.ts/js was always required. -This PR prevents confusion when Middleware isn’t recognized after a pageExtensions change. ### How? Edited docs/app/api-reference/file-conventions/middleware.mdx. Inserted a > **Note** block right after the paragraph explaining where to create the middleware file. Closes NEXT- Fixes #84008 --> --------- Co-authored-by: Joseph <[email protected]>
1 parent 0c846de commit 961a0f5

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/01-app/03-api-reference/03-file-conventions/middleware.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Middleware executes before routes are rendered. It's particularly useful for imp
2020
2121
Create a `middleware.ts` (or `.js`) file in the project root, or inside `src` if applicable, so that it is located at the same level as `pages` or `app`.
2222

23+
If you’ve customized [`pageExtensions`](/docs/app/api-reference/config/next-config-js/pageExtensions), for example to `.page.ts` or `.page.js`, name your file `middleware.page.ts` or `middleware.page.js` accordingly.
24+
2325
```tsx filename="middleware.ts" switcher
2426
import { NextResponse, NextRequest } from 'next/server'
2527

0 commit comments

Comments
 (0)