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
[NEXT-696] New middleware slows down routing in production #38273
Comments
Looks same so, but I got no error or slow work when no checks inside, like this: import { NextResponse } from 'next/server';
const Middleware = (req) => {
return NextResponse.next();
};
export default Middleware; |
I suppose this can also play a part in the performance degradation I filed in an issue a bit earlier: |
Also seeing this, also seeing the lack of slowdown when there are no checks / redirects as per @ch3rn1k's example. With 12.3, too. |
Well, same as before. Removed middleware when problem is started and no in use for me until this will be fixed. |
Also seeing this, tried it on 12.3.2 canary and the issue persists, we're talking massive slowdown. Everything was normal in the old _middleware.ts which was used in /pages |
I can confirm that the issue persists with node version 16.18.0 or 16.17.1. In any node version 16.5.0 and lower that I have tested the issue does not exist |
It may or may not be relevant that the middleware is now re-initialized on each request when in dev mode, rather than being initialized only once and then persisting like in previous versions. |
We are experiencing slow down when middleware is used together with large number of redirects. Probably because it affects also client side routing as described in documentation: "Redirects are not applied to client-side routing (Link, router.push), unless Middleware is present and matches the path." Any idea how we can handle 30-60k of redirects of old urls (which cannot be changed to rules)? |
The problem also exists in the 13 release. Just the presence of a middleware increases the response time tenfold. I did a test with a fresh next@canary release and a request to http://localhost:3000/vercel.svg takes 4ms without middleware.
Is enough to drop the response time |
@ch3rn1k @imangm @willemliufdmg @jalada @TurkaljGoran @11koukou @michal-hans @cdev-enter Does this change not fix the problem? #42547 |
@baraeb92 in 13.0.3-canary.1 this still exists. |
updating from 13.0.2 to the latest canary release fixed the issue in my project |
Having the same problem with the latest release 😢 |
Without a fix for this, the framework is basically unusable right now ... |
It s not only in production. It happens in dev also. I just tested middleware.js with next 12.3.3 and it works perfectly. When replacing next version with 13.0.4, i get +1 second load time on my page. |
Do we have any update on this issue? Is it acknowledged by the Next team? |
Also having same problem. Wait time is too high. Because of that Web Core Vitals hurting. |
Also having this issue - is there any previous version of Next / middleware that doesn't suffer from this? |
I think |
Can anyone provide a reproduction? I think it will get resolved faster if there is a reproduction that the NextJS team can take a look at? |
Next.js v13.0.7 still extremely slow, to a point where middleware is literally unusable |
Can't confirm this with v13.0.7. Strangely enough, everything looks fine , I had this issue with previous releases and I definitely know how it is. Tested in node version 16.14.1 and 16.18.0 |
Even in development environment? Tested it on pretty much every version from 13.0 to the latest one without any success. |
Adding a matcher to exclude resources helped in my case, of course it depends on your use case, in my case I didn't need a middleware for api/resources calls:
|
|
Same issues. Middleware, even with a lot of exceptions, slows down (dev & production) builds. |
I've tested this out with: So it appears #42547 did solve the issue for production only. However, The delay is still quite disruptive while working on dev. I understand cache is disabled on the dev build to allow the compiler to catch code changes, but since the |
thanks this improved the performance a little bit |
Has Anyone solved this problem? |
Verify canary release
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Binaries:
Node: 16.14.2
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 12.2.0
eslint-config-next: 12.2.0
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
Chrome 103.0.5060.66
How are you deploying your application? (if relevant)
next start
Describe the Bug
New middleware slows down on routing in production (dev is okay), example code that slows down:
Expected Behavior
Work as expected with no slow down, with previous
_middleware.js
there was no problemTo Reproduce
Create
middleware.js
file under root folder and use code from exampleNEXT-696
The text was updated successfully, but these errors were encountered: