Skip to content

Commit c4d4ce4

Browse files
committed
Don't warn on well-known properties
1 parent c69f05f commit c4d4ce4

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

packages/next/src/server/request/search-params.ts

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
describeStringPropertyAccess,
2121
describeHasCheckingStringProperty,
2222
throwWithStaticGenerationBailoutErrorWithDynamicError,
23+
wellKnownProperties,
2324
} from './utils'
2425

2526
export type SearchParams = { [key: string]: string | string[] | undefined }
@@ -567,63 +568,37 @@ function makeDynamicallyTrackedExoticSearchParamsWithDevWarnings(
567568
})
568569

569570
Object.keys(underlyingSearchParams).forEach((prop) => {
570-
switch (prop) {
571-
// Object prototype
572-
case 'hasOwnProperty':
573-
case 'isPrototypeOf':
574-
case 'propertyIsEnumerable':
575-
case 'toString':
576-
case 'valueOf':
577-
case 'toLocaleString':
578-
579-
// Promise prototype
580-
// fallthrough
581-
case 'then':
582-
case 'catch':
583-
case 'finally':
584-
585-
// React Promise extension
586-
// fallthrough
587-
case 'status':
588-
589-
// Common tested properties
590-
// fallthrough
591-
case 'toJSON':
592-
case '$$typeof':
593-
case '__esModule': {
594-
// These properties cannot be shadowed because they need to be the
595-
// true underlying value for Promises to work correctly at runtime
596-
unproxiedProperties.push(prop)
597-
break
598-
}
599-
default: {
600-
proxiedProperties.add(prop)
601-
Object.defineProperty(promise, prop, {
602-
get() {
603-
return proxiedUnderlying[prop]
604-
},
605-
set(newValue) {
606-
Object.defineProperty(promise, prop, {
607-
value: newValue,
608-
writable: true,
609-
enumerable: true,
610-
})
611-
},
612-
enumerable: true,
613-
configurable: true,
614-
})
615-
}
571+
if (wellKnownProperties.has(prop)) {
572+
// These properties cannot be shadowed because they need to be the
573+
// true underlying value for Promises to work correctly at runtime
574+
unproxiedProperties.push(prop)
575+
} else {
576+
proxiedProperties.add(prop)
577+
Object.defineProperty(promise, prop, {
578+
get() {
579+
return proxiedUnderlying[prop]
580+
},
581+
set(newValue) {
582+
Object.defineProperty(promise, prop, {
583+
value: newValue,
584+
writable: true,
585+
enumerable: true,
586+
})
587+
},
588+
enumerable: true,
589+
configurable: true,
590+
})
616591
}
617592
})
618593

619594
const proxiedPromise = new Proxy(promise, {
620595
get(target, prop, receiver) {
621596
if (typeof prop === 'string') {
622597
if (
623-
// We are accessing a property that was proxied to the promise instance
624-
proxiedProperties.has(prop) ||
625-
// We are accessing a property that doesn't exist on the promise nor the underlying
626-
Reflect.has(target, prop) === false
598+
!wellKnownProperties.has(prop) && // We are accessing a property that was proxied to the promise instance
599+
(proxiedProperties.has(prop) ||
600+
// We are accessing a property that doesn't exist on the promise nor the underlying
601+
Reflect.has(target, prop) === false)
627602
) {
628603
const expression = describeStringPropertyAccess('searchParams', prop)
629604
warnForSyncAccess(store.route, expression)

packages/next/src/server/request/utils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,28 @@ export function throwWithStaticGenerationBailoutErrorWithDynamicError(
5353
`Route ${route} with \`dynamic = "error"\` couldn't be rendered statically because it used ${expression}. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`
5454
)
5555
}
56+
57+
export const wellKnownProperties = new Set([
58+
'hasOwnProperty',
59+
'isPrototypeOf',
60+
'propertyIsEnumerable',
61+
'toString',
62+
'valueOf',
63+
'toLocaleString',
64+
65+
// Promise prototype
66+
// fallthrough
67+
'then',
68+
'catch',
69+
'finally',
70+
71+
// React Promise extension
72+
// fallthrough
73+
'status',
74+
75+
// Common tested properties
76+
// fallthrough
77+
'toJSON',
78+
'$$typeof',
79+
'__esModule',
80+
])

0 commit comments

Comments
 (0)