Skip to content

Commit b05a139

Browse files
authored
Revert "[metadata] new metadata insertion API and support PPR (#75366)"
This reverts commit 2220d73.
1 parent ef6ecdb commit b05a139

File tree

33 files changed

+92
-668
lines changed

33 files changed

+92
-668
lines changed

packages/next/src/client/components/router-reducer/ppr-navigations.ts

+3
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,9 @@ function finishPendingCacheNode(
797797
// a pending promise that needs to be resolved with the dynamic head from
798798
// the server.
799799
const head = cacheNode.head
800+
// TODO: change head back to ReactNode when metadata
801+
// is stably rendered in body
802+
// Handle head[0] - viewport
800803
if (isDeferredRsc(head)) {
801804
head.resolve(dynamicHead)
802805
}

packages/next/src/export/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export interface ExportPageInput {
6262
nextConfigOutput?: NextConfigComplete['output']
6363
enableExperimentalReact?: boolean
6464
sriEnabled: boolean
65-
streamingMetadata: boolean | undefined
6665
}
6766

6867
export type ExportRouteResult =

packages/next/src/export/worker.ts

-9
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,6 @@ async function exportPageImpl(
253253
)
254254
}
255255

256-
// During the export phase in next build, if it's using PPR we can serve streaming metadata
257-
// when it's available. When we're building the PPR rendering result, we don't need to rely
258-
// on the user agent. The result can be determined to serve streaming on infrastructure level.
259-
const serveStreamingMetadata = Boolean(
260-
isRoutePPREnabled && input.streamingMetadata
261-
)
262-
263256
const renderOpts: WorkerRenderOpts = {
264257
...components,
265258
...input.renderOpts,
@@ -269,7 +262,6 @@ async function exportPageImpl(
269262
disableOptimizedLoading,
270263
locale,
271264
supportsDynamicResponse: false,
272-
serveStreamingMetadata,
273265
experimental: {
274266
...input.renderOpts.experimental,
275267
isRoutePPREnabled,
@@ -424,7 +416,6 @@ export async function exportPages(
424416
debugOutput: options.debugOutput,
425417
enableExperimentalReact: needsExperimentalReact(nextConfig),
426418
sriEnabled: Boolean(nextConfig.experimental.sri?.algorithm),
427-
streamingMetadata: nextConfig.experimental.streamingMetadata,
428419
buildId: input.buildId,
429420
}),
430421
// If exporting the page takes longer than the timeout, reject the promise.

packages/next/src/lib/metadata/async-metadata.tsx

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
'use client'
22

3-
import { use, type JSX } from 'react'
4-
import { useServerInsertedMetadata } from '../../server/app-render/metadata-insertion/use-server-inserted-metadata'
3+
import { use } from 'react'
4+
import { useServerInsertedHTML } from '../../client/components/navigation'
55

6-
function ServerInsertMetadata({ promise }: { promise: Promise<JSX.Element> }) {
7-
// Apply use() to the metadata promise to suspend the rendering in SSR.
8-
const metadata = use(promise)
9-
// Insert metadata into the HTML stream through the `useServerInsertedMetadata`
10-
useServerInsertedMetadata(() => metadata)
6+
// We need to wait for metadata on server once it's resolved, and insert into
7+
// the HTML through `useServerInsertedHTML`. It will suspense in <head> during SSR.
8+
function ServerInsertMetadata({ promise }: { promise: Promise<any> }) {
9+
let metadataToFlush: React.ReactNode = use(promise)
10+
11+
useServerInsertedHTML(() => {
12+
if (metadataToFlush) {
13+
const flushing = metadataToFlush
14+
// reset to null to ensure we only flush it once
15+
metadataToFlush = null
16+
return flushing
17+
}
18+
})
1119

1220
return null
1321
}

packages/next/src/lib/metadata/metadata.tsx

+6-23
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { GetDynamicParamFromSegment } from '../../server/app-render/app-ren
33
import type { LoaderTree } from '../../server/lib/app-dir-module'
44
import type { CreateServerParamsForMetadata } from '../../server/request/params'
55

6-
import { Suspense, cache, cloneElement } from 'react'
6+
import { cache, cloneElement } from 'react'
77
import {
88
AppleWebAppMeta,
99
FormatDetectionMeta,
@@ -38,7 +38,6 @@ import {
3838
VIEWPORT_BOUNDARY_NAME,
3939
} from './metadata-constants'
4040
import { AsyncMetadata } from './async-metadata'
41-
import { isPostpone } from '../../server/lib/router-utils/is-postpone'
4241

4342
// Use a promise to share the status of the metadata resolving,
4443
// returning two components `MetadataTree` and `MetadataOutlet`
@@ -148,8 +147,8 @@ export function createMetadataComponents({
148147
async function resolveFinalMetadata() {
149148
try {
150149
return await metadata()
151-
} catch (metadataErr) {
152-
if (!errorType && isHTTPAccessFallbackError(metadataErr)) {
150+
} catch (error) {
151+
if (!errorType && isHTTPAccessFallbackError(error)) {
153152
try {
154153
return await getNotFoundMetadata(
155154
tree,
@@ -159,18 +158,7 @@ export function createMetadataComponents({
159158
createServerParamsForMetadata,
160159
workStore
161160
)
162-
} catch (notFoundMetadataErr) {
163-
// In PPR rendering we still need to throw the postpone error.
164-
// If metadata is postponed, React needs to be aware of the location of error.
165-
if (isPostpone(notFoundMetadataErr)) {
166-
throw notFoundMetadataErr
167-
}
168-
}
169-
}
170-
// In PPR rendering we still need to throw the postpone error.
171-
// If metadata is postponed, React needs to be aware of the location of error.
172-
if (isPostpone(metadataErr)) {
173-
throw metadataErr
161+
} catch {}
174162
}
175163
// We don't actually want to error in this component. We will
176164
// also error in the MetadataOutlet which causes the error to
@@ -180,15 +168,10 @@ export function createMetadataComponents({
180168
}
181169
}
182170
async function Metadata() {
183-
const promise = resolveFinalMetadata()
184171
if (serveStreamingMetadata) {
185-
return (
186-
<Suspense fallback={null}>
187-
<AsyncMetadata promise={promise} />
188-
</Suspense>
189-
)
172+
return <AsyncMetadata promise={resolveFinalMetadata()} />
190173
}
191-
return await promise
174+
return await resolveFinalMetadata()
192175
}
193176

194177
Metadata.displayName = METADATA_BOUNDARY_NAME

0 commit comments

Comments
 (0)