Unverified Commit af694f66 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix app metadata in edge runtime (#47941)

Seems edge runtime started failing for app paths from `path` being added
in https://github.com/vercel/next.js/pull/47829 so this updates to use
the isomorphic version instead and adds a regression test.

Fixes NEXT-866
parent df9de3de
......@@ -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'
......@@ -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'
......
'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
}
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,
},
}
......@@ -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)
......
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "**/*.test.ts"]
}
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