From 4d22dbca3f16e8bb999fd5bc6d1b904e224560e8 Mon Sep 17 00:00:00 2001 From: Yoshihiro Ashida Date: Tue, 17 Nov 2026 23:27:48 +0900 Subject: [PATCH 1/2] fix(metadata): render the remaining Metadata fields Next.js renders abstract, classification, archives, assets, bookmarks, facebook, pinterest and verification.me had no output. A verification value given as a list became one comma-joined tag, format-detection ignored date and url, an empty other value rendered an empty tag, and an Apple startup image given as a string in a list lost its href. --- packages/vinext/src/shims/metadata.tsx | 109 +++++++++++++++++++------ tests/features.test.ts | 101 +++++++++++++++++++++++ 2 files changed, 184 insertions(+), 26 deletions(-) diff --git a/packages/vinext/src/shims/metadata.tsx b/packages/vinext/src/shims/metadata.tsx index 1323ec1c3e..4d39b849e8 100644 --- a/packages/vinext/src/shims/metadata.tsx +++ b/packages/vinext/src/shims/metadata.tsx @@ -274,24 +274,34 @@ export type Metadata = { types?: Record; }; verification?: { - google?: string; - yahoo?: string; - yandex?: string; - other?: Record; + google?: MetadataValueList; + yahoo?: MetadataValueList; + yandex?: MetadataValueList; + me?: MetadataValueList; + other?: Record; }; metadataBase?: URL | null; appleWebApp?: { capable?: boolean; title?: string; statusBarStyle?: string; - startupImage?: string | Array<{ url: string; media?: string }>; + startupImage?: AppleStartupImage | AppleStartupImage[]; }; formatDetection?: { - email?: boolean; - address?: boolean; telephone?: boolean; + date?: boolean; + address?: boolean; + email?: boolean; + url?: boolean; }; + abstract?: string | null; + archives?: string | string[] | null; + assets?: string | string[] | null; + bookmarks?: string | string[] | null; category?: string; + classification?: string | null; + facebook?: { appId?: string; admins?: string | string[] } | null; + pinterest?: { richPin?: string | boolean } | null; itunes?: { appId: string; appArgument?: string; @@ -306,10 +316,22 @@ export type Metadata = { windows_universal?: AppLinksWindows | AppLinksWindows[]; web?: AppLinksWeb | AppLinksWeb[]; }; - other?: Record; + other?: Record; [key: string]: unknown; }; +type MetadataValue = string | number | null | undefined; +type MetadataValueList = MetadataValue | MetadataValue[]; + +type AppleStartupImage = string | { url: string; media?: string }; + +/** One entry per value; Next.js renders no tag for an empty or missing one. */ +function metadataValues(value: MetadataValueList): string[] { + return (Array.isArray(value) ? value : [value]) + .filter((entry) => entry != null && entry !== "") + .map(String); +} + type AppLinksApple = { url: string | URL; app_store_id?: string | number; @@ -1114,20 +1136,34 @@ export function MetadataHead({ // Format detection if (metadata.formatDetection) { - const parts: string[] = []; - if (metadata.formatDetection.telephone === false) parts.push("telephone=no"); - if (metadata.formatDetection.address === false) parts.push("address=no"); - if (metadata.formatDetection.email === false) parts.push("email=no"); + const formatDetection = metadata.formatDetection; + const parts = (["telephone", "date", "address", "email", "url"] as const) + .filter((format) => formatDetection[format] === false) + .map((format) => `${format}=no`); if (parts.length > 0) { elements.push(); } } + if (metadata.abstract) { + elements.push(); + } + + for (const rel of ["archives", "assets", "bookmarks"] as const) { + for (const href of metadataValues(metadata[rel])) { + elements.push(); + } + } + // Category if (metadata.category) { elements.push(); } + if (metadata.classification) { + elements.push(); + } + // Robots if (metadata.robots) { if (typeof metadata.robots === "string") { @@ -1486,16 +1522,16 @@ export function MetadataHead({ // Verification if (metadata.verification) { const v = metadata.verification; - if (v.google) - elements.push(); - if (v.yahoo) elements.push(); - if (v.yandex) elements.push(); - if (v.other) { - for (const [name, content] of Object.entries(v.other)) { - const values = Array.isArray(content) ? content : [content]; - for (const val of values) { - elements.push(); - } + const verificationTags: [name: string, values: MetadataValueList][] = [ + ["google-site-verification", v.google], + ["y_key", v.yahoo], + ["yandex-verification", v.yandex], + ["me", v.me], + ...Object.entries(v.other ?? {}), + ]; + for (const [name, values] of verificationTags) { + for (const content of metadataValues(values)) { + elements.push(); } } } @@ -1519,8 +1555,9 @@ export function MetadataHead({ ); } if (awa.startupImage) { - const imgs = - typeof awa.startupImage === "string" ? [{ url: awa.startupImage }] : awa.startupImage; + const imgs = (Array.isArray(awa.startupImage) ? awa.startupImage : [awa.startupImage]).map( + (image) => (typeof image === "string" ? { url: image } : image), + ); for (const img of imgs) { elements.push( ); } + // Facebook + if (metadata.facebook) { + if (metadata.facebook.appId) { + elements.push(); + } + for (const admin of metadataValues(metadata.facebook.admins)) { + elements.push(); + } + } + + // Pinterest + if (metadata.pinterest && metadata.pinterest.richPin !== undefined) { + elements.push( + , + ); + } + // App Links if (metadata.appLinks) { const al = metadata.appLinks; @@ -1575,8 +1633,7 @@ export function MetadataHead({ // Other custom meta tags if (metadata.other) { for (const [name, content] of Object.entries(metadata.other)) { - const values = Array.isArray(content) ? content : [content]; - for (const val of values) { + for (const val of metadataValues(content)) { elements.push(); } } diff --git a/tests/features.test.ts b/tests/features.test.ts index a7eb124e6a..b593cfe427 100644 --- a/tests/features.test.ts +++ b/tests/features.test.ts @@ -3171,6 +3171,107 @@ describe("MetadataHead rendering", () => { expect(html).toContain('href="https://example.com/rss"'); }); + // The cases below follow createMetadataElements in Next.js 16.2.6 + // (packages/next/src/lib/metadata/metadata.tsx) and its resolvers. + it("renders abstract, classification and the archives, assets and bookmarks links", () => { + const html = renderMetadataToHtml( + { + abstract: "abs", + classification: "cls", + archives: ["/arch"], + assets: "/assets", + bookmarks: ["/bm1", "/bm2"], + }, + "/", + ); + expect(html).toContain(''); + expect(html).toContain(''); + expect(html).toContain( + '', + ); + }); + + it("renders facebook and pinterest tags", () => { + expect(renderMetadataToHtml({ facebook: { appId: "123" } }, "/")).toContain( + '', + ); + expect(renderMetadataToHtml({ facebook: { admins: ["1", "2"] } }, "/")).toContain( + '', + ); + expect(renderMetadataToHtml({ facebook: { admins: "1" } }, "/")).toContain( + '', + ); + expect(renderMetadataToHtml({ pinterest: { richPin: true } }, "/")).toContain( + '', + ); + expect(renderMetadataToHtml({ pinterest: { richPin: false } }, "/")).toContain( + '', + ); + }); + + it("renders one verification tag per value, including me", () => { + const html = renderMetadataToHtml( + { + verification: { + google: ["g1", "g2"], + yahoo: "yh", + yandex: 123, + me: ["me@example.com", "https://me.example"], + other: { foo: ["a", ""] }, + }, + }, + "/", + ); + expect(html).toBe( + [ + '', + '', + '', + '', + '', + '', + '', + ].join(""), + ); + }); + + it("lists every disabled format in format-detection", () => { + const html = renderMetadataToHtml( + { + formatDetection: { + telephone: false, + date: false, + address: false, + email: false, + url: false, + }, + }, + "/", + ); + expect(html).toBe( + '', + ); + }); + + it("skips empty values in other", () => { + const html = renderMetadataToHtml({ other: { a: "", b: [], c: ["x", ""], n: 3 } }, "/"); + expect(html).toBe(''); + }); + + it("renders an Apple startup image given as a string in a list", () => { + const html = renderMetadataToHtml( + { + appleWebApp: { + startupImage: ["/st.png", { url: "/st2.png", media: "(device-width: 768px)" }], + }, + }, + "/", + ); + expect(html).toContain( + '', + ); + }); + it("renders twitter:site and twitter:creator:id", () => { const html = renderToStaticMarkup( React.createElement(MetadataHead, { From 947187f014ac78f59bdc817f6bec1fded201c4f8 Mon Sep 17 00:00:00 2001 From: Yoshihiro Ashida Date: Tue, 17 Nov 2026 23:30:36 +0900 Subject: [PATCH 2/2] fix(metadata): merge other values that hold numbers across segments The merge guard accepted only strings, so a segment whose other held a number replaced its parent's tags instead of adding to them. --- packages/vinext/src/shims/metadata.tsx | 9 +++++---- tests/features.test.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/vinext/src/shims/metadata.tsx b/packages/vinext/src/shims/metadata.tsx index 4d39b849e8..cf18b3926a 100644 --- a/packages/vinext/src/shims/metadata.tsx +++ b/packages/vinext/src/shims/metadata.tsx @@ -459,10 +459,11 @@ function isPlainObject(value: unknown): value is Record { function isOtherMetadata(value: unknown): value is NonNullable { if (!isPlainObject(value)) return false; - return Object.values(value).every((item) => { - if (typeof item === "string") return true; - return Array.isArray(item) && item.every((nestedItem) => typeof nestedItem === "string"); - }); + const isValue = (item: unknown) => + item == null || typeof item === "string" || typeof item === "number"; + return Object.values(value).every((item) => + Array.isArray(item) ? item.every(isValue) : isValue(item), + ); } /** diff --git a/tests/features.test.ts b/tests/features.test.ts index b593cfe427..7165a3aa86 100644 --- a/tests/features.test.ts +++ b/tests/features.test.ts @@ -2700,6 +2700,14 @@ describe("metadata segment merge", () => { }); }); + it("merges other custom meta tags that hold numbers", () => { + const result = mergeMetadata([ + { other: { inherited: "keep" } }, + { other: { count: 3, list: [1, "x"] } }, + ]); + expect(result.other).toEqual({ inherited: "keep", count: 3, list: [1, "x"] }); + }); + it("preserves root openGraph when page does not override it", () => { const result = mergeMetadata([ { openGraph: { title: "OG Layout", siteName: "Site" } },