Unverified Commit c663876c authored by Josh Story's avatar Josh Story Committed by GitHub

Refactor metadata and viewport preloading (#77400)

metadata and viewport are attempted to be resolved concurrently even
when async functions are used via `generateMetadata` and
`generateViewport`. We call this preloading because we initiate the
generation ahead of time but if it turns out that any particular
generator requires the parent resolved values we can progressively
reveal these to each pending generator. This PR refactors the code a bit
to simplify and clarify this process. This is setting the stage to later
separate out the resolution of viewport from metadata since only
viewport is now blocking the root.
parent 3468f10c
import type { ResolvedMetadata } from './types/metadata-interface'
import type {
ResolvedMetadata,
ResolvedViewport,
} from './types/metadata-interface'
const TYPE_URL = '__METADATA_URL'
......@@ -17,7 +20,9 @@ function reviver(_key: string, val: any) {
return val
}
export function cloneMetadata(metadata: ResolvedMetadata): ResolvedMetadata {
export function cloneMetadata<T extends ResolvedMetadata | ResolvedViewport>(
metadata: T
): T {
const jsonString = JSON.stringify(metadata, replacer)
return JSON.parse(jsonString, reviver)
}
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