Skip to content

Commit 254c8dd

Browse files
devjiwonchoignoff
andcommitted
use workStoreUnit to throw
Co-authored-by: Josh Story <story@hey.com>
1 parent dacfcb6 commit 254c8dd

File tree

1 file changed

+2
-88
lines changed

1 file changed

+2
-88
lines changed

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

Lines changed: 2 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ReflectAdapter } from '../web/spec-extension/adapters/reflect'
44
import {
55
throwToInterruptStaticGeneration,
66
postponeWithTracking,
7-
trackDynamicDataInDynamicRender,
87
annotateDynamicAccess,
98
delayUntilRuntimeStage,
109
} from '../app-render/dynamic-rendering'
@@ -193,14 +192,7 @@ function createRenderSearchParams(
193192
// Semantically we only need the dev tracking when running in `next dev`
194193
// but since you would never use next dev with production NODE_ENV we use this
195194
// as a proxy so we can statically exclude this code from production builds.
196-
if (process.env.__NEXT_CACHE_COMPONENTS) {
197-
return makeUntrackedSearchParamsWithDevWarnings(
198-
underlyingSearchParams,
199-
workStore
200-
)
201-
}
202-
203-
return makeDynamicallyTrackedSearchParamsWithDevWarnings(
195+
return makeUntrackedSearchParamsWithDevWarnings(
204196
underlyingSearchParams,
205197
workStore
206198
)
@@ -504,7 +496,7 @@ function makeUntrackedSearchParams(
504496
return promise
505497
}
506498

507-
function makeDynamicallyTrackedSearchParamsWithDevWarnings(
499+
function makeUntrackedSearchParamsWithDevWarnings(
508500
underlyingSearchParams: SearchParams,
509501
store: WorkStore
510502
): Promise<SearchParams> {
@@ -533,10 +525,6 @@ function makeDynamicallyTrackedSearchParamsWithDevWarnings(
533525
expression
534526
)
535527
}
536-
const workUnitStore = workUnitAsyncStorage.getStore()
537-
if (workUnitStore) {
538-
trackDynamicDataInDynamicRender(workUnitStore)
539-
}
540528
}
541529
return ReflectAdapter.get(target, prop, receiver)
542530
},
@@ -644,80 +632,6 @@ function makeDynamicallyTrackedSearchParamsWithDevWarnings(
644632
return proxiedPromise
645633
}
646634

647-
function makeUntrackedSearchParamsWithDevWarnings(
648-
underlyingSearchParams: SearchParams,
649-
store: WorkStore
650-
): Promise<SearchParams> {
651-
const cachedSearchParams = CachedSearchParams.get(underlyingSearchParams)
652-
if (cachedSearchParams) {
653-
return cachedSearchParams
654-
}
655-
656-
const proxiedProperties = new Set<string>()
657-
const unproxiedProperties: Array<string> = []
658-
const promise = makeDevtoolsIOAwarePromise(underlyingSearchParams)
659-
660-
Object.keys(underlyingSearchParams).forEach((prop) => {
661-
if (wellKnownProperties.has(prop)) {
662-
// These properties cannot be shadowed because they need to be the
663-
// true underlying value for Promises to work correctly at runtime
664-
unproxiedProperties.push(prop)
665-
} else {
666-
proxiedProperties.add(prop)
667-
}
668-
})
669-
670-
const proxiedPromise = new Proxy(promise, {
671-
get(target, prop, receiver) {
672-
if (typeof prop === 'string') {
673-
if (
674-
!wellKnownProperties.has(prop) &&
675-
(proxiedProperties.has(prop) ||
676-
// We are accessing a property that doesn't exist on the promise nor
677-
// the underlying searchParams.
678-
Reflect.has(target, prop) === false)
679-
) {
680-
const expression = describeStringPropertyAccess('searchParams', prop)
681-
warnForSyncAccess(store.route, expression)
682-
}
683-
}
684-
return ReflectAdapter.get(target, prop, receiver)
685-
},
686-
set(target, prop, value, receiver) {
687-
if (typeof prop === 'string') {
688-
proxiedProperties.delete(prop)
689-
}
690-
return Reflect.set(target, prop, value, receiver)
691-
},
692-
has(target, prop) {
693-
if (typeof prop === 'string') {
694-
if (
695-
!wellKnownProperties.has(prop) &&
696-
(proxiedProperties.has(prop) ||
697-
// We are accessing a property that doesn't exist on the promise nor
698-
// the underlying searchParams.
699-
Reflect.has(target, prop) === false)
700-
) {
701-
const expression = describeHasCheckingStringProperty(
702-
'searchParams',
703-
prop
704-
)
705-
warnForSyncAccess(store.route, expression)
706-
}
707-
}
708-
return Reflect.has(target, prop)
709-
},
710-
ownKeys(target) {
711-
const expression = '`Object.keys(searchParams)` or similar'
712-
warnForIncompleteEnumeration(store.route, expression, unproxiedProperties)
713-
return Reflect.ownKeys(target)
714-
},
715-
})
716-
717-
CachedSearchParams.set(underlyingSearchParams, proxiedPromise)
718-
return proxiedPromise
719-
}
720-
721635
const warnForSyncAccess = createDedupedByCallsiteServerErrorLoggerDev(
722636
createSearchAccessError
723637
)

0 commit comments

Comments
 (0)