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

[ Possible Bug ] Next Images / Middleware Match Patterns #118

Closed
nikuscs opened this issue Aug 16, 2023 · 2 comments · Fixed by #119
Closed

[ Possible Bug ] Next Images / Middleware Match Patterns #118

nikuscs opened this issue Aug 16, 2023 · 2 comments · Fixed by #119
Labels
bug Something isn't working

Comments

@nikuscs
Copy link

nikuscs commented Aug 16, 2023

Hey! Thanks for the amazing package at first, really clean, ts, just magic!

I was trying in a fresh project on the latest next canary, while everything looks like working at glance, it seems like images being served from Next Images component are having issues, because the middleware actually looks for the original url path.

So lets say you have : "public/one.png" , thats the actual URL that arrives at the middleware and not "_next/images?url..."

For me it seems like next middleware should exclude public assets by default, but there should be reason why they didnt :p

Im not sure if this an actual upstream issue, but just wanted to mention i able to replicate this on your demo repo.

My suggestion for this would be either include the matches by default on your create middleware so users have a better DX by having stuff ignored out of the box.

This seems related to vercel/next.js#36308 (comment)

The solution for me was updated the following on the middleware.ts

export const config = {
  matcher: '/((?!api|static|.*\\..*|_next).*)',
}

Next Version: ^13.4.17-canary.0
Router: App Router

@QuiiBz
Copy link
Owner

QuiiBz commented Aug 17, 2023

That looks indeed like a Next.js issue, I don't think I can do anything at the library level apart from updating the matcher regex. The middleware API will also be updated in the v1 version which should be out soon, I'll include a I18nMiddleware.matcher field to make it easier.

@QuiiBz
Copy link
Owner

QuiiBz commented Aug 17, 2023

Just checked the Next.js docs and we won't be able to provide a variable for the matcher regex, because Next.js needs it to be statically analyzable:

Screenshot 2023-08-17 at 07 55 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants