Commit 12669a07 authored by Janka Uryga's avatar Janka Uryga

simplify metadata pathname promise creation

parent 63e373bf
...@@ -770,5 +770,6 @@ ...@@ -770,5 +770,6 @@
"769": "createSearchParamsFromClient should not be called in a runtime prerender.", "769": "createSearchParamsFromClient should not be called in a runtime prerender.",
"770": "createParamsFromClient should not be called in a runtime prerender.", "770": "createParamsFromClient should not be called in a runtime prerender.",
"771": "\\`%s\\` was called during a runtime prerender. Next.js should be preventing %s from being included in server components statically, but did not in this case.", "771": "\\`%s\\` was called during a runtime prerender. Next.js should be preventing %s from being included in server components statically, but did not in this case.",
"772": "FetchStrategy.PPRRuntime should never be used when `experimental.clientSegmentCache` is disabled" "772": "FetchStrategy.PPRRuntime should never be used when `experimental.clientSegmentCache` is disabled",
"773": "createServerPathnameForMetadata was called inside a client component scope."
} }
...@@ -5,10 +5,7 @@ import { ...@@ -5,10 +5,7 @@ import {
type DynamicTrackingState, type DynamicTrackingState,
} from '../app-render/dynamic-rendering' } from '../app-render/dynamic-rendering'
import { import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external'
workUnitAsyncStorage,
type StaticPrerenderStore,
} from '../app-render/work-unit-async-storage.external'
import { makeHangingPromise } from '../dynamic-rendering-utils' import { makeHangingPromise } from '../dynamic-rendering-utils'
import { InvariantError } from '../../shared/lib/invariant-error' import { InvariantError } from '../../shared/lib/invariant-error'
...@@ -19,23 +16,36 @@ export function createServerPathnameForMetadata( ...@@ -19,23 +16,36 @@ export function createServerPathnameForMetadata(
const workUnitStore = workUnitAsyncStorage.getStore() const workUnitStore = workUnitAsyncStorage.getStore()
if (workUnitStore) { if (workUnitStore) {
switch (workUnitStore.type) { switch (workUnitStore.type) {
case 'prerender': case 'prerender': {
case 'prerender-client': const fallbackParams = workUnitStore.fallbackRouteParams
case 'prerender-ppr': if (fallbackParams && fallbackParams.size > 0) {
case 'prerender-legacy': { return makeHangingPromise<string>(
return createPrerenderPathname( workUnitStore.renderSignal,
underlyingPathname, '`pathname`'
workStore, )
workUnitStore }
break
}
case 'prerender-client': {
throw new InvariantError(
'createServerPathnameForMetadata was called inside a client component scope.'
) )
} }
case 'prerender-ppr': {
const fallbackParams = workUnitStore.fallbackRouteParams
if (fallbackParams && fallbackParams.size > 0) {
return makeErroringPathname(workStore, workUnitStore.dynamicTracking)
}
break
}
case 'cache': case 'cache':
case 'private-cache': case 'private-cache':
case 'unstable-cache': case 'unstable-cache': {
throw new InvariantError( throw new InvariantError(
'createServerPathnameForMetadata should not be called in cache contexts.' 'createServerPathnameForMetadata should not be called in cache contexts.'
) )
}
case 'prerender-legacy':
case 'prerender-runtime': case 'prerender-runtime':
case 'request': case 'request':
break break
...@@ -43,43 +53,6 @@ export function createServerPathnameForMetadata( ...@@ -43,43 +53,6 @@ export function createServerPathnameForMetadata(
workUnitStore satisfies never workUnitStore satisfies never
} }
} }
return createRenderPathname(underlyingPathname)
}
function createPrerenderPathname(
underlyingPathname: string,
workStore: WorkStore,
prerenderStore: StaticPrerenderStore
): Promise<string> {
switch (prerenderStore.type) {
case 'prerender-client':
throw new InvariantError(
'createPrerenderPathname was called inside a client component scope.'
)
case 'prerender': {
const fallbackParams = prerenderStore.fallbackRouteParams
if (fallbackParams && fallbackParams.size > 0) {
return makeHangingPromise<string>(
prerenderStore.renderSignal,
'`pathname`'
)
}
break
}
case 'prerender-ppr': {
const fallbackParams = prerenderStore.fallbackRouteParams
if (fallbackParams && fallbackParams.size > 0) {
return makeErroringPathname(workStore, prerenderStore.dynamicTracking)
}
break
}
case 'prerender-legacy':
break
default:
prerenderStore satisfies never
}
// We don't have any fallback params so we have an entirely static safe params object
return Promise.resolve(underlyingPathname) return Promise.resolve(underlyingPathname)
} }
...@@ -117,7 +90,3 @@ function makeErroringPathname<T>( ...@@ -117,7 +90,3 @@ function makeErroringPathname<T>(
// the promise will call the `then` property triggering the lazy postpone // the promise will call the `then` property triggering the lazy postpone
return new Proxy(promise, {}) return new Proxy(promise, {})
} }
function createRenderPathname(underlyingPathname: string): Promise<string> {
return Promise.resolve(underlyingPathname)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment