-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace metadata clone with custom handler in dev (#49343)
- Loading branch information
Showing
5 changed files
with
50 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { ResolvedMetadata } from './types/metadata-interface' | ||
|
||
const TYPE_URL = '__METADATA_URL' | ||
|
||
function replacer(_key: string, val: any) { | ||
// clone URL as string but recover it as URL | ||
if (val instanceof URL) { | ||
return { _type: TYPE_URL, value: val.href } | ||
} | ||
return val | ||
} | ||
|
||
function reviver(_key: string, val: any) { | ||
if (typeof val === 'object' && val !== null && val._type === TYPE_URL) { | ||
return new URL(val.value) | ||
} | ||
return val | ||
} | ||
|
||
export function cloneMetadata(metadata: ResolvedMetadata): ResolvedMetadata { | ||
const jsonString = JSON.stringify(metadata, replacer) | ||
return JSON.parse(jsonString, reviver) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/e2e/app-dir/metadata/app/opengraph/article/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default function Layout({ children }) { | ||
return children | ||
} | ||
|
||
export const metadata = { | ||
openGraph: { | ||
title: 'Layout open graph title', | ||
description: 'My custom description', | ||
type: 'article', | ||
publishedTime: '2023-01-01T00:00:00.000Z', | ||
authors: ['author1', 'author2', 'author3'], | ||
images: new URL('https://example.com/og-image.jpg'), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters