We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
https://github.com/willwill96/nextjs-after-function-repro
http://localhost:3000
Current Behavior: after blocks within middleware functions are executed before page render begins
after
Expected Behavior: From the docs
after allows you to schedule work to be executed after a response (or prerender) is finished.
Based on this, I expect after blocks within middleware functions to be executed after page render is finished.
Operating System: Platform: linux Arch: x64 Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024 Available memory (MB): 47749 Available CPU cores: 16 Binaries: Node: 22.12.0 npm: 10.9.0 Yarn: 1.22.22 pnpm: N/A Relevant Packages: next: 15.1.4 // Latest available version is detected (15.1.4). eslint-config-next: 15.1.4 react: 19.0.0 react-dom: 19.0.0 typescript: 5.7.3 Next.js Config: output: N/A
Middleware
next dev (local), next start (local), next build (local)
Example Application Output:
Middleware Timing - Start 14041.842787 Middleware Timing - End 14042.483035 Page Timing - Start 14060.135459 GET / 200 in 27ms Page Timing - End 14069.832975
Relevant code:
import { after, NextRequest, NextResponse } from "next/server"; export async function middleware(req: NextRequest) { if (req.url === 'http://localhost:3000/') { console.log("Middleware Timing - Start", performance.now()) after(()=>{ console.log("Middleware Timing - End", performance.now()) }) } return NextResponse.next() }
import { after } from "next/server"; export default function Home() { console.log("Page Timing - Start", performance.now()) after(()=>{ console.log("Page Timing - End", performance.now()) }) return ( <div className..... ); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Link to the code that reproduces this issue
https://github.com/willwill96/nextjs-after-function-repro
To Reproduce
http://localhost:3000
through preferred methodCurrent vs. Expected behavior
Current Behavior:
after
blocks within middleware functions are executed before page render beginsExpected Behavior:
From the docs
Based on this, I expect
after
blocks within middleware functions to be executed after page render is finished.Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024 Available memory (MB): 47749 Available CPU cores: 16 Binaries: Node: 22.12.0 npm: 10.9.0 Yarn: 1.22.22 pnpm: N/A Relevant Packages: next: 15.1.4 // Latest available version is detected (15.1.4). eslint-config-next: 15.1.4 react: 19.0.0 react-dom: 19.0.0 typescript: 5.7.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Middleware
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local), next build (local)
Additional context
Example Application Output:
Relevant code:
The text was updated successfully, but these errors were encountered: