mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
`Math.random()` is IO though it is synchronous. When `dynamicIO` is enabled we need to treat calls to `Math.random()` as IO and exclude them from prerenders unless they are cached. This change sets up the instrumentation for this behavior. Unless the sync access of async request APIs this patch does not yet have any dev warnings. These will be added in a future update when we can instrument the environment name during dev to tell the difference between the prerender phase, and render phase even without a build
9 lines
287 B
TypeScript
9 lines
287 B
TypeScript
import { NextResponse } from 'next/server'
|
|
import type { NextRequest } from 'next/server'
|
|
|
|
export function middleware(request: NextRequest) {
|
|
if (Math.random() > -1 && request.nextUrl.pathname === '/rewrite') {
|
|
return NextResponse.rewrite(new URL('/rewritten', request.url))
|
|
}
|
|
}
|