@@ -3,6 +3,7 @@ import { NextURL } from '../next-url'
33import { toNodeOutgoingHttpHeaders , validateURL } from '../utils'
44import { RemovedUAError , RemovedPageError } from '../error'
55import { RequestCookies } from './cookies'
6+ import type { BaseNextRequest } from '../../base-http'
67
78export const INTERNALS = Symbol ( 'internal request' )
89
@@ -22,7 +23,7 @@ export class NextRequest extends Request {
2223 const url =
2324 typeof input !== 'string' && 'url' in input ? input . url : String ( input )
2425 validateURL ( url )
25- if ( input instanceof Request ) super ( input , init )
26+ if ( typeof input === 'object' ) super ( input , init )
2627 else super ( url , init )
2728 const nextUrl = new NextURL ( url , {
2829 headers : toNodeOutgoingHttpHeaders ( this . headers ) ,
@@ -88,6 +89,10 @@ export class NextRequest extends Request {
8889 public get url ( ) {
8990 return this [ INTERNALS ] . url
9091 }
92+
93+ public clone ( ) {
94+ return new NextRequest ( super . clone ( ) )
95+ }
9196}
9297
9398export interface RequestInit extends globalThis . RequestInit {
@@ -98,3 +103,14 @@ export interface RequestInit extends globalThis.RequestInit {
98103 }
99104 signal ?: AbortSignal
100105}
106+
107+ /**
108+ * When `NextRequest` is used accross bundle boundaries, an `instanceof` check
109+ * will not work. Instead, this helper function can be used to discriminate
110+ * between `NextRequest` and `BaseNextRequest`.
111+ */
112+ export function isNextRequest (
113+ req : NextRequest | BaseNextRequest
114+ ) : req is NextRequest {
115+ return 'nextUrl' in req
116+ }
0 commit comments