Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix app metadata in edge runtime #47941

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function nextMetadataImageLoader(this: any, content: Buffer) {
if (isDynamicResource) {
// re-export and spread as `exportedImageData` to avoid non-exported error
return `\
import path from 'path'
import path from 'next/dist/shared/lib/isomorphic/path'
import * as exported from ${JSON.stringify(resourcePath)}
import { interpolateDynamicPath } from 'next/dist/server/server-utils'
import { getNamedRouteRegex } from 'next/dist/shared/lib/router/utils/route-regex'
Expand Down Expand Up @@ -105,7 +105,7 @@ async function nextMetadataImageLoader(this: any, content: Buffer) {
}

return `\
import path from 'path'
import path from 'next/dist/shared/lib/isomorphic/path'
import { interpolateDynamicPath } from 'next/dist/server/server-utils'
import { getNamedRouteRegex } from 'next/dist/shared/lib/router/utils/route-regex'

Expand Down
14 changes: 14 additions & 0 deletions test/e2e/app-dir/metadata/app/basic-edge/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client'

import ReactDOM from 'react-dom'

// NOTE: atm preload/prefetch/prefetchDNS are only supported in the SSR and client, not in RSC yet
export default function Client() {
// @ts-ignore
ReactDOM.preload('/preload-url', { as: 'script' })
// @ts-ignore
ReactDOM.preconnect('/preconnect-url', { crossOrigin: 'use-credentials' })
// @ts-ignore
ReactDOM.prefetchDNS('/dns-prefetch-url')
return null
}
46 changes: 46 additions & 0 deletions test/e2e/app-dir/metadata/app/basic-edge/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Metadata } from 'next'
import Link from 'next/link'
import Client from './client'

export const runtime = 'experimental-edge'

export default function Page() {
return (
<div id="basic">
<Link id="to-index" href="/">
to index
</Link>
<br />
<Link href="/title-template/extra/inner" id="to-nested">
to /title-template/extra/inner
</Link>
<Client />
</div>
)
}

export const metadata: Metadata = {
generator: 'next.js',
applicationName: 'test',
referrer: 'origin-when-cross-origin',
keywords: ['next.js', 'react', 'javascript'],
authors: [{ name: 'huozhi' }, { name: 'tree', url: 'https://tree.com' }],
themeColor: { color: 'cyan', media: '(prefers-color-scheme: dark)' },
colorScheme: 'dark',
manifest: 'https://www.google.com/manifest',
viewport: {
width: 'device-width',
initialScale: 1,
maximumScale: 1,
interactiveWidget: 'resizes-visual',
},
creator: 'shu',
publisher: 'vercel',
robots: 'index, follow',
alternates: {},
formatDetection: {
email: false,
address: false,
telephone: false,
},
}
34 changes: 34 additions & 0 deletions test/e2e/app-dir/metadata/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,40 @@ createNextDescribe(
})
})

it('should support other basic tags (edge)', async () => {
const browser = await next.browser('/basic-edge')
const matchDom = createDomMatcher(browser)
const matchMultiDom = createMultiDomMatcher(browser)

await matchMultiDom('meta', 'name', 'content', {
generator: 'next.js',
'application-name': 'test',
referrer: 'origin-when-cross-origin',
keywords: 'next.js,react,javascript',
author: ['huozhi', 'tree'],
'color-scheme': 'dark',
viewport:
'width=device-width, initial-scale=1, maximum-scale=1, interactive-widget=resizes-visual',
creator: 'shu',
publisher: 'vercel',
robots: 'index, follow',
'format-detection': 'telephone=no, address=no, email=no',
})

await matchMultiDom('link', 'rel', 'href', {
manifest: 'https://www.google.com/manifest',
author: 'https://tree.com',
preconnect: '/preconnect-url',
preload: '/preload-url',
'dns-prefetch': '/dns-prefetch-url',
})

await matchDom('meta', 'name="theme-color"', {
media: '(prefers-color-scheme: dark)',
content: 'cyan',
})
})

it('should support apple related tags `itunes` and `appWebApp`', async () => {
const browser = await next.browser('/apple')
const matchMultiDom = createMultiDomMatcher(browser)
Expand Down
25 changes: 0 additions & 25 deletions test/e2e/app-dir/metadata/tsconfig.json

This file was deleted.