From 273bd28db09e180ff994eaf0b1d4972688fe65ea Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 27 Mar 2023 14:11:07 +0200 Subject: [PATCH 1/7] Provide default metadataBase for local and vercel deployment always resolve full url for opengraph images update ut types hoist logs metadataBase in dev revert test fix lint and test fix test fix test --- .../src/lib/metadata/default-metadata.tsx | 9 +++-- .../metadata/resolvers/resolve-opengraph.ts | 4 +-- .../src/lib/metadata/resolvers/resolve-url.ts | 13 ++++++-- .../next/src/server/app-render/app-render.tsx | 1 + .../metadata-dynamic-routes/app/page.tsx | 1 - .../metadata-dynamic-routes/index.test.ts | 33 ++++++++++++++----- test/e2e/app-dir/metadata/metadata.test.ts | 8 ++--- 7 files changed, 49 insertions(+), 20 deletions(-) diff --git a/packages/next/src/lib/metadata/default-metadata.tsx b/packages/next/src/lib/metadata/default-metadata.tsx index 8dbd0d192bb91..c8f9dfd3c843c 100644 --- a/packages/next/src/lib/metadata/default-metadata.tsx +++ b/packages/next/src/lib/metadata/default-metadata.tsx @@ -1,12 +1,17 @@ import React from 'react' import type { ResolvedMetadata } from './types/metadata-interface' -export const createDefaultMetadata = (): ResolvedMetadata => { +export function createDefaultMetadata(): ResolvedMetadata { + let defaultMetadataBase = new URL('http://n') + if (process.env.NODE_ENV === 'production' && process.env.VERCEL_URL) { + defaultMetadataBase = new URL(`https://${process.env.VERCEL_URL}`) + } + return { viewport: 'width=device-width, initial-scale=1', + metadataBase: defaultMetadataBase, // Other values are all null - metadataBase: null, title: null, description: null, applicationName: null, diff --git a/packages/next/src/lib/metadata/resolvers/resolve-opengraph.ts b/packages/next/src/lib/metadata/resolvers/resolve-opengraph.ts index b3da5fea361e8..3923e28767e3b 100644 --- a/packages/next/src/lib/metadata/resolvers/resolve-opengraph.ts +++ b/packages/next/src/lib/metadata/resolvers/resolve-opengraph.ts @@ -43,11 +43,11 @@ function resolveImages( resolvedImages?.forEach((item, index, array) => { if (isStringOrURL(item)) { array[index] = { - url: metadataBase ? resolveUrl(item, metadataBase)! : item, + url: resolveUrl(item, metadataBase)!, } } else { // Update image descriptor url - item.url = metadataBase ? resolveUrl(item.url, metadataBase)! : item.url + item.url = resolveUrl(item.url, metadataBase)! } }) return resolvedImages diff --git a/packages/next/src/lib/metadata/resolvers/resolve-url.ts b/packages/next/src/lib/metadata/resolvers/resolve-url.ts index 6fc89ddfc72fe..4e28089d531c8 100644 --- a/packages/next/src/lib/metadata/resolvers/resolve-url.ts +++ b/packages/next/src/lib/metadata/resolvers/resolve-url.ts @@ -1,4 +1,5 @@ import path from '../../../shared/lib/isomorphic/path' +import { warnOnce } from '../../../shared/lib/utils/warn-once' function isStringOrURL(icon: any): icon is string | URL { return typeof icon === 'string' || icon instanceof URL @@ -17,10 +18,18 @@ function resolveUrl( return parsedUrl } catch (_) {} - if (!metadataBase) + if (!metadataBase) { throw new Error( - `metadata.metadataBase needs to be provided for resolving absolute URLs: ${url}` + `metadata.metadataBase needs to be provided for resolving absolute URL: ${url}` ) + } + if (metadataBase.origin === 'http://n') { + metadataBase = new URL('http://localhost:3000') + // Development mode warning + warnOnce( + `"metadataBase" is not set and fallbacks to "http://localhost:3000", Please specify it in root layout to resolve urls as absolute` + ) + } // Handle relative or absolute paths const basePath = metadataBase.pathname || '/' diff --git a/packages/next/src/server/app-render/app-render.tsx b/packages/next/src/server/app-render/app-render.tsx index 1390d26165759..09ce516be333d 100644 --- a/packages/next/src/server/app-render/app-render.tsx +++ b/packages/next/src/server/app-render/app-render.tsx @@ -1037,6 +1037,7 @@ export async function renderToHTMLOrFlight( ), + // {/* `http://localhost:3000${req.url}` */} injectedCSS: new Set(), injectedFontPreloadTags: new Set(), rootLayoutIncluded: false, diff --git a/test/e2e/app-dir/metadata-dynamic-routes/app/page.tsx b/test/e2e/app-dir/metadata-dynamic-routes/app/page.tsx index c2dd96ac06cea..eba737535cc7e 100644 --- a/test/e2e/app-dir/metadata-dynamic-routes/app/page.tsx +++ b/test/e2e/app-dir/metadata-dynamic-routes/app/page.tsx @@ -5,6 +5,5 @@ export default function Page() { } export const metadata = { - metadataBase: new URL('https://deploy-preview-abc.vercel.app'), title: 'index page', } diff --git a/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts b/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts index a959e295b26ce..2caaef4e9d63f 100644 --- a/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts +++ b/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts @@ -13,12 +13,11 @@ createNextDescribe( 'app dir - metadata dynamic routes', { files: __dirname, - skipDeployment: true, dependencies: { '@vercel/og': '0.4.1', }, }, - ({ next, isNextDev }) => { + ({ next, isNextDev, isNextDeploy }) => { describe('text routes', () => { it('should handle robots.[ext] dynamic routes', async () => { const res = await next.fetch('/robots.txt') @@ -148,6 +147,10 @@ createNextDescribe( }) it('should inject dynamic metadata properly to head', async () => { + const logs = [] + next.on('stderr', (log) => { + logs.push(log) + }) const $ = await next.render$('/') const $icon = $('link[rel="icon"]') const $appleIcon = $('link[rel="apple-touch-icon"]') @@ -158,6 +161,14 @@ createNextDescribe( 'content' ) + if (isNextDev) { + expect( + logs.includes( + `"metadataBase" is not set and fallbacks to "http://localhost:3000", Please specify it in root layout to resolve urls as absolute\n` + ) + ).toBe(true) + } + // non absolute urls expect($icon.attr('href')).toContain('/icon') expect($icon.attr('href')).toMatch(hashRegex) @@ -172,14 +183,18 @@ createNextDescribe( expect(twitterTitle).toBe('Twitter - Next.js App') expect(twitterDescription).toBe('Twitter - This is a Next.js App') - // absolute urls - expect(ogImageUrl).toContain( - `https://deploy-preview-abc.vercel.app/opengraph-image` - ) + if (isNextDeploy) { + // absolute urls + expect(ogImageUrl).toMatch(/https:\/\/\w+.vercel.app\/opengraph-image/) + expect(twitterImageUrl).toMatch( + /https:\/\/\w+.vercel.app\/twitter-image/ + ) + } else { + // absolute urls + expect(ogImageUrl).toMatch(/http:\/\/localhost:\d+\/opengraph-image/) + expect(twitterImageUrl).toMatch(/http:\/\/localhost:\d+\/twitter-image/) + } expect(ogImageUrl).toMatch(hashRegex) - expect(twitterImageUrl).toContain( - `https://deploy-preview-abc.vercel.app/twitter-image` - ) expect(twitterImageUrl).toMatch(hashRegex) // alt text diff --git a/test/e2e/app-dir/metadata/metadata.test.ts b/test/e2e/app-dir/metadata/metadata.test.ts index f97a5797b81d8..f438d3e5374d8 100644 --- a/test/e2e/app-dir/metadata/metadata.test.ts +++ b/test/e2e/app-dir/metadata/metadata.test.ts @@ -257,7 +257,7 @@ createNextDescribe( it('should support alternate tags', async () => { const browser = await next.browser('/alternate') - await checkLink(browser, 'canonical', 'https://example.com') + await checkLink(browser, 'canonical', 'https://example.com/') await checkMeta( browser, 'en-US', @@ -277,7 +277,7 @@ createNextDescribe( await checkMeta( browser, 'only screen and (max-width: 600px)', - '/mobile', + 'http://localhost:3000/mobile', 'media', 'link', 'href' @@ -286,11 +286,11 @@ createNextDescribe( await matchDom('link', 'title="js title"', { type: 'application/rss+xml', - href: 'blog/js.rss', + href: 'http://localhost:3000/blog/js.rss', }) await matchDom('link', 'title="rss"', { type: 'application/rss+xml', - href: 'blog.rss', + href: 'http://localhost:3000/blog.rss', }) }) From 3ef437af7ebd99f58ac2503c0939c45cbd094a20 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 28 Mar 2023 16:03:07 +0200 Subject: [PATCH 2/7] use empty metadata for test case --- .../next/src/lib/metadata/resolve-metadata.ts | 6 +++++- .../src/lib/metadata/resolvers/resolve-url.ts | 4 ++-- .../metadata-dynamic-routes/index.test.ts | 6 ++++-- .../app-dir/metadata/app/alternate/page.tsx | 5 +++-- test/e2e/app-dir/metadata/metadata.test.ts | 20 +++++++++++-------- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/packages/next/src/lib/metadata/resolve-metadata.ts b/packages/next/src/lib/metadata/resolve-metadata.ts index 14b35233435b0..e48b379e75e76 100644 --- a/packages/next/src/lib/metadata/resolve-metadata.ts +++ b/packages/next/src/lib/metadata/resolve-metadata.ts @@ -82,7 +82,11 @@ function merge( openGraph: string | null } ) { - const metadataBase = source?.metadataBase || target.metadataBase + // If there's override metadata, prefer it otherwise fallback to the default metadata. + const metadataBase = + typeof source?.metadataBase !== 'undefined' + ? source.metadataBase + : source?.metadataBase || target.metadataBase for (const key_ in source) { const key = key_ as keyof Metadata diff --git a/packages/next/src/lib/metadata/resolvers/resolve-url.ts b/packages/next/src/lib/metadata/resolvers/resolve-url.ts index 4e28089d531c8..1bc5b48553540 100644 --- a/packages/next/src/lib/metadata/resolvers/resolve-url.ts +++ b/packages/next/src/lib/metadata/resolvers/resolve-url.ts @@ -24,10 +24,10 @@ function resolveUrl( ) } if (metadataBase.origin === 'http://n') { - metadataBase = new URL('http://localhost:3000') + metadataBase = new URL(`http://localhost:${process.env.PORT || 3000}`) // Development mode warning warnOnce( - `"metadataBase" is not set and fallbacks to "http://localhost:3000", Please specify it in root layout to resolve urls as absolute` + `"metadataBase" is not set and fallbacks to "${metadataBase.origin}", please specify it in root layout to resolve absolute urls.` ) } diff --git a/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts b/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts index 2caaef4e9d63f..8dd22f1c0c7ec 100644 --- a/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts +++ b/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts @@ -163,8 +163,10 @@ createNextDescribe( if (isNextDev) { expect( - logs.includes( - `"metadataBase" is not set and fallbacks to "http://localhost:3000", Please specify it in root layout to resolve urls as absolute\n` + logs.some((log) => + /"metadataBase" is not set and fallbacks to "http:\/\/localhost:\d+", please specify it in root layout to resolve absolute urls/.test( + log + ) ) ).toBe(true) } diff --git a/test/e2e/app-dir/metadata/app/alternate/page.tsx b/test/e2e/app-dir/metadata/app/alternate/page.tsx index 2ef6cc58eb651..16d1e7dbc6353 100644 --- a/test/e2e/app-dir/metadata/app/alternate/page.tsx +++ b/test/e2e/app-dir/metadata/app/alternate/page.tsx @@ -3,6 +3,7 @@ export default function Page() { } export const metadata = { + metadataBase: null, alternates: { canonical: 'https://example.com', languages: { @@ -14,8 +15,8 @@ export const metadata = { }, types: { 'application/rss+xml': [ - { url: 'blog.rss', title: 'rss' }, - { url: 'blog/js.rss', title: 'js title' }, + { url: '/blog.rss', title: 'rss' }, + { url: '/blog/js.rss', title: 'js title' }, ], }, }, diff --git a/test/e2e/app-dir/metadata/metadata.test.ts b/test/e2e/app-dir/metadata/metadata.test.ts index f438d3e5374d8..32c07482a4604 100644 --- a/test/e2e/app-dir/metadata/metadata.test.ts +++ b/test/e2e/app-dir/metadata/metadata.test.ts @@ -16,7 +16,7 @@ createNextDescribe( async function checkMeta( browser: BrowserInterface, queryValue: string, - expected: string | string[] | undefined | null, + expected: RegExp | string | string[] | undefined | null, queryKey: string = 'property', tag: string = 'meta', domAttributeField: string = 'content' @@ -24,10 +24,14 @@ createNextDescribe( const values = await browser.eval( `[...document.querySelectorAll('${tag}[${queryKey}="${queryValue}"]')].map((el) => el.getAttribute("${domAttributeField}"))` ) - if (Array.isArray(expected)) { - expect(values).toEqual(expected) + if (expected instanceof RegExp) { + expect(values[0]).toMatch(expected) } else { - expect(values[0]).toBe(expected) + if (Array.isArray(expected)) { + expect(values).toEqual(expected) + } else { + expect(values[0]).toBe(expected) + } } } @@ -257,7 +261,7 @@ createNextDescribe( it('should support alternate tags', async () => { const browser = await next.browser('/alternate') - await checkLink(browser, 'canonical', 'https://example.com/') + await checkLink(browser, 'canonical', 'https://example.com') await checkMeta( browser, 'en-US', @@ -277,7 +281,7 @@ createNextDescribe( await checkMeta( browser, 'only screen and (max-width: 600px)', - 'http://localhost:3000/mobile', + '/mobile', 'media', 'link', 'href' @@ -286,11 +290,11 @@ createNextDescribe( await matchDom('link', 'title="js title"', { type: 'application/rss+xml', - href: 'http://localhost:3000/blog/js.rss', + href: '/blog/js.rss', }) await matchDom('link', 'title="rss"', { type: 'application/rss+xml', - href: 'http://localhost:3000/blog.rss', + href: '/blog.rss', }) }) From 6dbe72de70f398a8f98c4be8105605a05b2c1f7f Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 29 Mar 2023 20:13:58 +0200 Subject: [PATCH 3/7] error when missing metadataBase in prod --- .../src/lib/metadata/default-metadata.tsx | 8 +-- .../src/lib/metadata/resolvers/resolve-url.ts | 21 +++--- .../metadata-dynamic-routes/app/layout.tsx | 3 + .../metadata-dynamic-routes/index.test.ts | 14 ---- .../app/layout.js | 12 ++++ .../app/opengraph-image.js | 23 +++++++ .../app/page.js | 9 +++ .../index.test.ts | 68 +++++++++++++++++++ .../next.config.js | 3 + 9 files changed, 133 insertions(+), 28 deletions(-) create mode 100644 test/e2e/app-dir/metadata-missing-metadata-base/app/layout.js create mode 100644 test/e2e/app-dir/metadata-missing-metadata-base/app/opengraph-image.js create mode 100644 test/e2e/app-dir/metadata-missing-metadata-base/app/page.js create mode 100644 test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts create mode 100644 test/e2e/app-dir/metadata-missing-metadata-base/next.config.js diff --git a/packages/next/src/lib/metadata/default-metadata.tsx b/packages/next/src/lib/metadata/default-metadata.tsx index c8f9dfd3c843c..3b418e89cdcd1 100644 --- a/packages/next/src/lib/metadata/default-metadata.tsx +++ b/packages/next/src/lib/metadata/default-metadata.tsx @@ -2,10 +2,10 @@ import React from 'react' import type { ResolvedMetadata } from './types/metadata-interface' export function createDefaultMetadata(): ResolvedMetadata { - let defaultMetadataBase = new URL('http://n') - if (process.env.NODE_ENV === 'production' && process.env.VERCEL_URL) { - defaultMetadataBase = new URL(`https://${process.env.VERCEL_URL}`) - } + const defaultMetadataBase = + process.env.NODE_ENV === 'production' && process.env.VERCEL_URL + ? new URL(`https://${process.env.VERCEL_URL}`) + : null return { viewport: 'width=device-width, initial-scale=1', diff --git a/packages/next/src/lib/metadata/resolvers/resolve-url.ts b/packages/next/src/lib/metadata/resolvers/resolve-url.ts index 1bc5b48553540..ab35431bfe1d6 100644 --- a/packages/next/src/lib/metadata/resolvers/resolve-url.ts +++ b/packages/next/src/lib/metadata/resolvers/resolve-url.ts @@ -19,16 +19,17 @@ function resolveUrl( } catch (_) {} if (!metadataBase) { - throw new Error( - `metadata.metadataBase needs to be provided for resolving absolute URL: ${url}` - ) - } - if (metadataBase.origin === 'http://n') { - metadataBase = new URL(`http://localhost:${process.env.PORT || 3000}`) - // Development mode warning - warnOnce( - `"metadataBase" is not set and fallbacks to "${metadataBase.origin}", please specify it in root layout to resolve absolute urls.` - ) + if (process.env.NODE_ENV !== 'production') { + metadataBase = new URL(`http://localhost:${process.env.PORT || 3000}`) + // Development mode warning + warnOnce( + `metadata.metadataBase is not set and fallbacks to "${metadataBase.origin}", please specify it in root layout to resolve absolute urls.` + ) + } else { + throw new Error( + `metadata.metadataBase needs to be provided for resolving absolute URL: ${url}` + ) + } } // Handle relative or absolute paths diff --git a/test/e2e/app-dir/metadata-dynamic-routes/app/layout.tsx b/test/e2e/app-dir/metadata-dynamic-routes/app/layout.tsx index b7dd2b8561c6b..2e96e371aa4ff 100644 --- a/test/e2e/app-dir/metadata-dynamic-routes/app/layout.tsx +++ b/test/e2e/app-dir/metadata-dynamic-routes/app/layout.tsx @@ -8,6 +8,9 @@ export default function Layout({ children }) { } export const metadata = { + metadataBase: process.env.VERCEL_URL + ? new URL(`https://${process.env.VERCEL_URL}`) + : new URL(`http://localhost:${process.env.PORT || 3000}`), title: 'Next.js App', description: 'This is a Next.js App', twitter: { diff --git a/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts b/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts index 8dd22f1c0c7ec..1db3159ad9b53 100644 --- a/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts +++ b/test/e2e/app-dir/metadata-dynamic-routes/index.test.ts @@ -147,10 +147,6 @@ createNextDescribe( }) it('should inject dynamic metadata properly to head', async () => { - const logs = [] - next.on('stderr', (log) => { - logs.push(log) - }) const $ = await next.render$('/') const $icon = $('link[rel="icon"]') const $appleIcon = $('link[rel="apple-touch-icon"]') @@ -161,16 +157,6 @@ createNextDescribe( 'content' ) - if (isNextDev) { - expect( - logs.some((log) => - /"metadataBase" is not set and fallbacks to "http:\/\/localhost:\d+", please specify it in root layout to resolve absolute urls/.test( - log - ) - ) - ).toBe(true) - } - // non absolute urls expect($icon.attr('href')).toContain('/icon') expect($icon.attr('href')).toMatch(hashRegex) diff --git a/test/e2e/app-dir/metadata-missing-metadata-base/app/layout.js b/test/e2e/app-dir/metadata-missing-metadata-base/app/layout.js new file mode 100644 index 0000000000000..28dde49b94080 --- /dev/null +++ b/test/e2e/app-dir/metadata-missing-metadata-base/app/layout.js @@ -0,0 +1,12 @@ +export default function Layout({ children }) { + return ( + + + {children} + + ) +} + +export const metadata = { + title: 'Next.js App', +} diff --git a/test/e2e/app-dir/metadata-missing-metadata-base/app/opengraph-image.js b/test/e2e/app-dir/metadata-missing-metadata-base/app/opengraph-image.js new file mode 100644 index 0000000000000..fd72c819260e1 --- /dev/null +++ b/test/e2e/app-dir/metadata-missing-metadata-base/app/opengraph-image.js @@ -0,0 +1,23 @@ +import { ImageResponse } from '@vercel/og' + +export const alt = 'Open Graph' + +export default function og() { + return new ImageResponse( + ( +
+ Open Graph +
+ ) + ) +} diff --git a/test/e2e/app-dir/metadata-missing-metadata-base/app/page.js b/test/e2e/app-dir/metadata-missing-metadata-base/app/page.js new file mode 100644 index 0000000000000..eba737535cc7e --- /dev/null +++ b/test/e2e/app-dir/metadata-missing-metadata-base/app/page.js @@ -0,0 +1,9 @@ +import React from 'react' + +export default function Page() { + return <>hello index +} + +export const metadata = { + title: 'index page', +} diff --git a/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts b/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts new file mode 100644 index 0000000000000..d432bea417de4 --- /dev/null +++ b/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts @@ -0,0 +1,68 @@ +import { createNext, FileRef } from 'e2e-utils' +import { NextInstance } from 'test/lib/next-modes/base' +import { createNextDescribe } from 'e2e-utils' +import { fetchViaHTTP } from 'next-test-utils' + +describe('app dir - metadata missing metadataBase', () => { + let next: NextInstance + // const logs = [] + + beforeAll(async () => { + next = await createNext({ + skipStart: true, + dependencies: { + '@vercel/og': 'latest', + }, + files: new FileRef(__dirname), + }) + // next.on('stderr', (log) => { + // logs.push(log) + // }) + }) + afterAll(() => next.destroy()) + + if (globalThis.isNextDev) { + it('should warning in development', async () => { + await next.start() + await fetchViaHTTP(next.url, '/') + expect(next.cliOutput).toInclude( + 'metadata.metadataBase is not set and fallbacks to "http://localhost:' + ) + expect(next.cliOutput).toInclude( + 'please specify it in root layout to resolve absolute urls.' + ) + }) + } else { + it('should error in production', async () => { + await expect(next.start()).rejects.toThrow('next build failed') + expect(next.cliOutput).toInclude( + 'metadata.metadataBase needs to be provided for resolving absolute URL: /opengraph-image?' + ) + }) + } +}) + +// createNextDescribe( +// 'app dir - metadata missing metadataBase', +// { +// files: __dirname, +// dependencies: { +// '@vercel/og': '0.4.1', +// }, +// }, +// ({ next, isNextDev, isNextStart }) => { + +// if (isNextDev) { +// console.log('logs', logs) +// expect( +// logs.some((log) => +// /metadata\.metadataBase is not set and fallbacks to "http:\/\/localhost:\d+", please specify it in root layout to resolve absolute urls/.test( +// log +// ) +// ) +// ).toBe(true) +// } else if (isNextStart) { + +// } +// } +// ) diff --git a/test/e2e/app-dir/metadata-missing-metadata-base/next.config.js b/test/e2e/app-dir/metadata-missing-metadata-base/next.config.js new file mode 100644 index 0000000000000..8e2a6c3691744 --- /dev/null +++ b/test/e2e/app-dir/metadata-missing-metadata-base/next.config.js @@ -0,0 +1,3 @@ +module.exports = { + experimental: { appDir: true }, +} From 2edb6ddf64700fec4e5ea14590629b2aa937635b Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 29 Mar 2023 20:20:07 +0200 Subject: [PATCH 4/7] rm comment --- packages/next/src/server/app-render/app-render.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/next/src/server/app-render/app-render.tsx b/packages/next/src/server/app-render/app-render.tsx index 09ce516be333d..1390d26165759 100644 --- a/packages/next/src/server/app-render/app-render.tsx +++ b/packages/next/src/server/app-render/app-render.tsx @@ -1037,7 +1037,6 @@ export async function renderToHTMLOrFlight( ), - // {/* `http://localhost:3000${req.url}` */} injectedCSS: new Set(), injectedFontPreloadTags: new Set(), rootLayoutIncluded: false, From 4e7ae69bf6d059a994e2787b2269b7a16c8a4a13 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 29 Mar 2023 20:38:11 +0200 Subject: [PATCH 5/7] fix lint --- test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts b/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts index d432bea417de4..756160d3f1992 100644 --- a/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts +++ b/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts @@ -1,6 +1,5 @@ import { createNext, FileRef } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' -import { createNextDescribe } from 'e2e-utils' import { fetchViaHTTP } from 'next-test-utils' describe('app dir - metadata missing metadataBase', () => { From 05c0380bf562b91a2be08afe5ce88aa439e83d04 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 29 Mar 2023 23:55:29 +0200 Subject: [PATCH 6/7] remove useless cond --- packages/next/src/lib/metadata/resolve-metadata.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/lib/metadata/resolve-metadata.ts b/packages/next/src/lib/metadata/resolve-metadata.ts index e48b379e75e76..4364243f120bd 100644 --- a/packages/next/src/lib/metadata/resolve-metadata.ts +++ b/packages/next/src/lib/metadata/resolve-metadata.ts @@ -86,7 +86,7 @@ function merge( const metadataBase = typeof source?.metadataBase !== 'undefined' ? source.metadataBase - : source?.metadataBase || target.metadataBase + : target.metadataBase for (const key_ in source) { const key = key_ as keyof Metadata From 64c84fded27c0a840c85baac11b88eab272e1505 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 30 Mar 2023 18:31:40 +0200 Subject: [PATCH 7/7] rm comments --- .../index.test.ts | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts b/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts index 756160d3f1992..993772b6d6c54 100644 --- a/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts +++ b/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts @@ -4,7 +4,6 @@ import { fetchViaHTTP } from 'next-test-utils' describe('app dir - metadata missing metadataBase', () => { let next: NextInstance - // const logs = [] beforeAll(async () => { next = await createNext({ @@ -14,9 +13,6 @@ describe('app dir - metadata missing metadataBase', () => { }, files: new FileRef(__dirname), }) - // next.on('stderr', (log) => { - // logs.push(log) - // }) }) afterAll(() => next.destroy()) @@ -40,28 +36,3 @@ describe('app dir - metadata missing metadataBase', () => { }) } }) - -// createNextDescribe( -// 'app dir - metadata missing metadataBase', -// { -// files: __dirname, -// dependencies: { -// '@vercel/og': '0.4.1', -// }, -// }, -// ({ next, isNextDev, isNextStart }) => { - -// if (isNextDev) { -// console.log('logs', logs) -// expect( -// logs.some((log) => -// /metadata\.metadataBase is not set and fallbacks to "http:\/\/localhost:\d+", please specify it in root layout to resolve absolute urls/.test( -// log -// ) -// ) -// ).toBe(true) -// } else if (isNextStart) { - -// } -// } -// )