Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug?: new MiddlewareConfig type doesn't match runtime behavior and docs #61705

Closed
juliusmarminge opened this issue Feb 6, 2024 · 3 comments · Fixed by #61718 · May be fixed by #67331
Closed

bug?: new MiddlewareConfig type doesn't match runtime behavior and docs #61705

juliusmarminge opened this issue Feb 6, 2024 · 3 comments · Fixed by #61718 · May be fixed by #67331
Labels
linear: next Confirmed issue that is tracked by the Next.js team. locked TypeScript Related to types with Next.js.

Comments

@juliusmarminge
Copy link
Contributor

juliusmarminge commented Feb 6, 2024

Is this type correct? It doesn't match the docs where we can have a matcher: string attribute: https://nextjs.org/docs/app/building-your-application/routing/middleware#example

CleanShot 2024-02-06 at 09 10 37@2x

Originally posted by @juliusmarminge in #61576 (comment)

NEXT-2375

@juliusmarminge
Copy link
Contributor Author

juliusmarminge commented Feb 6, 2024

Reproduction repo if needed: https://github.com/juliusmarminge/next-auth-type-mismatch

Output of next info:

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000
Binaries:
  Node: 20.11.0
  npm: 10.2.4
  Yarn: 1.22.19
  pnpm: 8.13.1
Relevant Packages:
  next: 14.1.1-canary.36 // Latest available version is detected (14.1.1-canary.36).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

@balazsorban44 balazsorban44 added linear: next Confirmed issue that is tracked by the Next.js team. TypeScript Related to types with Next.js. labels Feb 6, 2024
balazsorban44 added a commit that referenced this issue Feb 7, 2024
### What?

Fix the user-facing `MiddlewareConfig` interface.

~While in the codebase, I also made the incoming config object type a
bit more strict by converting from `any` to `unknown`.~ Reverted, as we
do a config assertion already in a [different
place](https://github.com/vercel/next.js/blob/canary/packages/next-swc/crates/next-custom-transforms/src/transforms/page_config.rs/#L171-L180).

### Why?

The interface we previously exposed was the one we used internally,
_after_ we did some parsing on the config object, which is different
from what the user is expected to pass.

### How?

I separated the internal type to its own `MiddlewareConfigParsed`
interface.

Closes NEXT-2375
Fixes #61705

Ref: #61576
@apostolos
Copy link
Contributor

apostolos commented Feb 8, 2024

@balazsorban44 This is still not fixed.

image

The interface MiddlewareMatcher has regexp and originalSource whereas the runtime expects source.

Following the types results in Next.js dying with the following error message:

source` is missing, invalid fields: originalSource,regexp for route {"originalSource":"/:path*","regexp":"/((?!api|_next/static|_next/image|favicon.ico).*)","missing":[{"type":"header","key":"next-router-prefetch"},{"type":"header","key":"purpose","value":"prefetch"}]}

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
linear: next Confirmed issue that is tracked by the Next.js team. locked TypeScript Related to types with Next.js.
Projects
None yet
3 participants