@@ -21,10 +21,9 @@ import {
21
21
} from './generate/opengraph'
22
22
import { IconsMetadata } from './generate/icons'
23
23
import {
24
- resolveMetadataItems ,
25
- accumulateMetadata ,
26
- accumulateViewport ,
27
24
type MetadataErrorType ,
25
+ resolveMetadata ,
26
+ resolveViewport ,
28
27
} from './resolve-metadata'
29
28
import { MetaFilter } from './generate/meta'
30
29
import type {
@@ -196,24 +195,14 @@ async function getResolvedMetadataImpl(
196
195
errorType ?: MetadataErrorType | 'redirect'
197
196
) : Promise < React . ReactNode > {
198
197
const errorConvention = errorType === 'redirect' ? undefined : errorType
199
-
200
- const metadataItems = await resolveMetadataItems (
198
+ return renderMetadata (
201
199
tree ,
202
200
searchParams ,
203
- errorConvention ,
204
201
getDynamicParamFromSegment ,
202
+ metadataContext ,
205
203
createServerParamsForMetadata ,
206
- workStore
207
- )
208
- const elements : Array < React . ReactNode > = createMetadataElements (
209
- await accumulateMetadata ( metadataItems , metadataContext )
210
- )
211
- return (
212
- < >
213
- { elements . map ( ( el , index ) => {
214
- return cloneElement ( el as React . ReactElement , { key : index } )
215
- } ) }
216
- </ >
204
+ workStore ,
205
+ errorConvention
217
206
)
218
207
}
219
208
@@ -227,24 +216,14 @@ async function getNotFoundMetadataImpl(
227
216
workStore : WorkStore
228
217
) : Promise < React . ReactNode > {
229
218
const notFoundErrorConvention = 'not-found'
230
- const notFoundMetadataItems = await resolveMetadataItems (
219
+ return renderMetadata (
231
220
tree ,
232
221
searchParams ,
233
- notFoundErrorConvention ,
234
222
getDynamicParamFromSegment ,
223
+ metadataContext ,
235
224
createServerParamsForMetadata ,
236
- workStore
237
- )
238
-
239
- const elements : Array < React . ReactNode > = createMetadataElements (
240
- await accumulateMetadata ( notFoundMetadataItems , metadataContext )
241
- )
242
- return (
243
- < >
244
- { elements . map ( ( el , index ) => {
245
- return cloneElement ( el as React . ReactElement , { key : index } )
246
- } ) }
247
- </ >
225
+ workStore ,
226
+ notFoundErrorConvention
248
227
)
249
228
}
250
229
@@ -258,18 +237,55 @@ async function getResolvedViewportImpl(
258
237
errorType ?: MetadataErrorType | 'redirect'
259
238
) : Promise < React . ReactNode > {
260
239
const errorConvention = errorType === 'redirect' ? undefined : errorType
240
+ return renderViewport (
241
+ tree ,
242
+ searchParams ,
243
+ getDynamicParamFromSegment ,
244
+ createServerParamsForMetadata ,
245
+ workStore ,
246
+ errorConvention
247
+ )
248
+ }
261
249
262
- const metadataItems = await resolveMetadataItems (
250
+ const getNotFoundViewport = cache ( getNotFoundViewportImpl )
251
+ async function getNotFoundViewportImpl (
252
+ tree : LoaderTree ,
253
+ searchParams : Promise < ParsedUrlQuery > ,
254
+ getDynamicParamFromSegment : GetDynamicParamFromSegment ,
255
+ createServerParamsForMetadata : CreateServerParamsForMetadata ,
256
+ workStore : WorkStore
257
+ ) : Promise < React . ReactNode > {
258
+ const notFoundErrorConvention = 'not-found'
259
+ return renderViewport (
263
260
tree ,
264
261
searchParams ,
265
- errorConvention ,
266
262
getDynamicParamFromSegment ,
267
263
createServerParamsForMetadata ,
268
- workStore
264
+ workStore ,
265
+ notFoundErrorConvention
269
266
)
270
- const elements : Array < React . ReactNode > = createViewportElements (
271
- await accumulateViewport ( metadataItems )
267
+ }
268
+
269
+ async function renderMetadata (
270
+ tree : LoaderTree ,
271
+ searchParams : Promise < ParsedUrlQuery > ,
272
+ getDynamicParamFromSegment : GetDynamicParamFromSegment ,
273
+ metadataContext : MetadataContext ,
274
+ createServerParamsForMetadata : CreateServerParamsForMetadata ,
275
+ workStore : WorkStore ,
276
+ errorConvention ?: MetadataErrorType
277
+ ) {
278
+ const resolvedMetadata = await resolveMetadata (
279
+ tree ,
280
+ searchParams ,
281
+ errorConvention ,
282
+ getDynamicParamFromSegment ,
283
+ createServerParamsForMetadata ,
284
+ workStore ,
285
+ metadataContext
272
286
)
287
+ const elements : Array < React . ReactNode > =
288
+ createMetadataElements ( resolvedMetadata )
273
289
return (
274
290
< >
275
291
{ elements . map ( ( el , index ) => {
@@ -279,26 +295,25 @@ async function getResolvedViewportImpl(
279
295
)
280
296
}
281
297
282
- const getNotFoundViewport = cache ( getNotFoundViewportImpl )
283
- async function getNotFoundViewportImpl (
298
+ async function renderViewport (
284
299
tree : LoaderTree ,
285
300
searchParams : Promise < ParsedUrlQuery > ,
286
301
getDynamicParamFromSegment : GetDynamicParamFromSegment ,
287
302
createServerParamsForMetadata : CreateServerParamsForMetadata ,
288
- workStore : WorkStore
289
- ) : Promise < React . ReactNode > {
290
- const notFoundErrorConvention = 'not-found'
291
- const notFoundMetadataItems = await resolveMetadataItems (
303
+ workStore : WorkStore ,
304
+ errorConvention ?: MetadataErrorType
305
+ ) {
306
+ const notFoundResolvedViewport = await resolveViewport (
292
307
tree ,
293
308
searchParams ,
294
- notFoundErrorConvention ,
309
+ errorConvention ,
295
310
getDynamicParamFromSegment ,
296
311
createServerParamsForMetadata ,
297
312
workStore
298
313
)
299
314
300
315
const elements : Array < React . ReactNode > = createViewportElements (
301
- await accumulateViewport ( notFoundMetadataItems )
316
+ notFoundResolvedViewport
302
317
)
303
318
return (
304
319
< >
0 commit comments