Skip to content

fix: use page extensions for middleware files#595

Draft
james-elicx wants to merge 1 commit intomainfrom
opencode/glowing-squid
Draft

fix: use page extensions for middleware files#595
james-elicx wants to merge 1 commit intomainfrom
opencode/glowing-squid

Conversation

@james-elicx
Copy link
Collaborator

middleware and proxy files should use next config page extensions where available, similar to routes.

@james-elicx
Copy link
Collaborator Author

/bigbonk review

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 19, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@595

commit: 231c67f

@github-actions
Copy link

Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original

Copy link
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

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

Good change — middleware/proxy file discovery should respect pageExtensions just like route scanning does. The ordering fix in index.ts (moving the call after config is loaded) is correct, and the tests cover the new behavior well.

Two things to consider:

.mjs regression risk — The old hardcoded lists included .mjs for both proxy and middleware files. The default pageExtensions are ["tsx", "ts", "jsx", "js"], which does not include mjs. Any existing project with proxy.mjs or middleware.mjs that hasn't explicitly added "mjs" to their pageExtensions in next.config.js will silently lose middleware detection after this change. This matches the route scanning behavior (which also wouldn't pick up .mjs routes without explicit config), so it's arguably correct — but it's a subtle breaking change worth noting in case anyone reports it.

findInstrumentationFile follow-upserver/instrumentation.ts still uses a hardcoded file list with the same pattern this PR is fixing. Worth a follow-up to update it for consistency.

@ask-bonk
Copy link
Contributor

ask-bonk bot commented Mar 19, 2026

Review posted on PR #595. Here's a summary of what I found:

The PR is solid. It unifies middleware/proxy file discovery with the same pageExtensions-based approach used for route scanning, replacing hardcoded file lists with fileMatcher.dottedExtensions. The ordering fix in index.ts (moving findMiddlewareFile after config load) is correct, and the new tests validate extension filtering and deprecation warnings.

I flagged two items:

  1. .mjs regression risk — The old hardcoded lists included .mjs, but default pageExtensions don't. Projects using proxy.mjs/middleware.mjs without explicit config would lose detection. This is arguably consistent with route behavior, but it's a subtle breaking change.

  2. findInstrumentationFile follow-upserver/instrumentation.ts still uses the same hardcoded pattern this PR is fixing, and should be updated for consistency.

github run

@james-elicx james-elicx force-pushed the opencode/glowing-squid branch from f3f3410 to 231c67f Compare March 19, 2026 20:28
@james-elicx james-elicx marked this pull request as draft March 19, 2026 20:33
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.

1 participant