Skip to content

Commit

Permalink
rootParams() is now a plain Proimse (not exotic) (vercel#75717)
Browse files Browse the repository at this point in the history
When we made Request data APIs async we made them exotic to make the
transition to the Promise API easier to adopt because lots of existing
code probably accessed these values synchronously. `rootParams` is a new
Request Data API however and it has no existing usage that is async so
we do not need to support exotic access to these values. This change
removes the exotic construction in favor of a simple resolved Promise.
  • Loading branch information
gnoff authored Feb 5, 2025
1 parent 444a182 commit 5fa487a
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions packages/next/src/server/request/root-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function unstable_rootParams(): Promise<Params> {
)
}

return makeUntrackedRootParams(underlyingParams)
return Promise.resolve(underlyingParams)
}
case 'prerender':
case 'prerender-ppr':
Expand All @@ -57,7 +57,7 @@ export async function unstable_rootParams(): Promise<Params> {
// fallthrough
}
}
return makeUntrackedRootParams(underlyingParams)
return Promise.resolve(underlyingParams)
}

function createPrerenderRootParams(
Expand Down Expand Up @@ -106,7 +106,7 @@ function createPrerenderRootParams(
}

// We don't have any fallback params so we have an entirely static safe params object
return makeUntrackedRootParams(underlyingParams)
return Promise.resolve(underlyingParams)
}

function makeErroringRootParams(
Expand Down Expand Up @@ -172,27 +172,3 @@ function makeErroringRootParams(

return promise
}

function makeUntrackedRootParams(underlyingParams: Params): Promise<Params> {
const cachedParams = CachedParams.get(underlyingParams)
if (cachedParams) {
return cachedParams
}

// We don't use makeResolvedReactPromise here because params
// supports copying with spread and we don't want to unnecessarily
// instrument the promise with spreadable properties of ReactPromise.
const promise = Promise.resolve(underlyingParams)
CachedParams.set(underlyingParams, promise)

Object.keys(underlyingParams).forEach((prop) => {
if (wellKnownProperties.has(prop)) {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
} else {
;(promise as any)[prop] = underlyingParams[prop]
}
})

return promise
}

0 comments on commit 5fa487a

Please sign in to comment.