-
Notifications
You must be signed in to change notification settings - Fork 27.9k
/
Copy pathinternal-utils.ts
39 lines (32 loc) · 1 KB
/
internal-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type { NextParsedUrlQuery } from './request-meta'
import { NEXT_RSC_UNION_QUERY } from '../client/components/app-router-headers'
const INTERNAL_QUERY_NAMES = [
'__nextFallback',
'__nextLocale',
'__nextInferredLocaleFromDefault',
'__nextDefaultLocale',
'__nextIsNotFound',
NEXT_RSC_UNION_QUERY,
] as const
const EDGE_EXTENDED_INTERNAL_QUERY_NAMES = ['__nextDataReq'] as const
export function stripInternalQueries(query: NextParsedUrlQuery) {
for (const name of INTERNAL_QUERY_NAMES) {
delete query[name]
}
}
export function stripInternalSearchParams<T extends string | URL>(
url: T,
isEdge: boolean
): T {
const isStringUrl = typeof url === 'string'
const instance = isStringUrl ? new URL(url) : (url as URL)
for (const name of INTERNAL_QUERY_NAMES) {
instance.searchParams.delete(name)
}
if (isEdge) {
for (const name of EDGE_EXTENDED_INTERNAL_QUERY_NAMES) {
instance.searchParams.delete(name)
}
}
return (isStringUrl ? instance.toString() : instance) as T
}