From 64806b77f19be624a4acd63c8b3b9dd5db1b2525 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Fri, 9 Aug 2024 10:54:31 +0200 Subject: [PATCH 1/7] Always collect static icons for all segments --- .../next/src/lib/metadata/resolve-metadata.ts | 12 ++++++------ .../app/@modal/blank.txt | 1 + .../app/apple-icon.png | Bin 0 -> 1661 bytes .../app/favicon.ico | Bin 0 -> 15086 bytes .../metadata-icons-parallel-routes/app/icon.svg | 14 ++++++++++++++ .../app/layout.js | 7 +++++++ .../metadata-icons-parallel-routes/app/page.js | 3 +++ .../metadata-icons-parallel-routes/app/test.png | Bin 0 -> 1661 bytes .../metadata-icons-parallel-routes.test.ts | 14 ++++++++++++++ 9 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/blank.txt create mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/app/apple-icon.png create mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/app/favicon.ico create mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/app/icon.svg create mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/app/layout.js create mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/app/page.js create mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/app/test.png create mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/metadata-icons-parallel-routes.test.ts diff --git a/packages/next/src/lib/metadata/resolve-metadata.ts b/packages/next/src/lib/metadata/resolve-metadata.ts index aa546db407baa..c81ec901e91ba 100644 --- a/packages/next/src/lib/metadata/resolve-metadata.ts +++ b/packages/next/src/lib/metadata/resolve-metadata.ts @@ -104,7 +104,12 @@ function mergeStaticMetadata( if (!staticFilesMetadata) return const { icon, apple, openGraph, twitter, manifest } = staticFilesMetadata - // Only pick up the static metadata if the current level is the last segment + if ((icon || apple) && !target.icons) { + target.icons = { + icon: icon || [], + apple: apple || [], + } + } if (isLastSegment) { // file based metadata is specified and current level metadata icons is not specified if (target.icons) { @@ -114,11 +119,6 @@ function mergeStaticMetadata( if (apple) { target.icons.apple.unshift(...apple) } - } else if (icon || apple) { - target.icons = { - icon: icon || [], - apple: apple || [], - } } } diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/blank.txt b/test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/blank.txt new file mode 100644 index 0000000000000..b4de6870aeb01 --- /dev/null +++ b/test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/blank.txt @@ -0,0 +1 @@ +This file is to mark the parallel route @modal existence diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/app/apple-icon.png b/test/e2e/app-dir/metadata-icons-parallel-routes/app/apple-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..7cbc1d26733614b83dcc25b9cfcd5e06dffb147c GIT binary patch literal 1661 zcmV-@27>vCP)LUUqAigYBsiM4LpbwXrcM#DLg%sv zqYV7atJ2!&9+4a}Z~>mx*QQG8O{j2%jKM&gp$l9QGmOhXo1ym@G1NiGAj_1lhANDV z1!S4frxq9i3di1^l$}15Gz3>C_2kBUE^I5>7jp>X5wdo&Pd!2a6f5GP)GgXa3QSQ5 zJ0>bk8Vt=;h$f0RQz4ot-b{sPqIfeEqKV?oREQ=HW#$APi4kKst#JY0qCFI7KO!;| z-{Dx5|6)LB*iF*ATe1cl&QpkEr#`hqi_TA*>5v*DyuQX9nwI%PlNUBUM=lW0iy@%% zB^BF?>xE4!QsG#Qk#JB|Zt7m}4cuf9&Sc^>nhincOJ6g{>L6IPUat?vOi^vN=pG%= zK#)fFriX`z1CgewsCHXKz1WKmEejx6qkEB3>Y%mGjoj^a`R9__Z&8YtD2$*QSF6?G zlq}0cwcn!FRXGQOH@cIk`fMagBI@t3C`Ai25VWzK_5A#7HS(IOas~u%Y$wfTvqK&8 z`CQcBV^O1VSn-#r$_`Ey)bSA>M>05=GHK|=D&vNW5yX)MHLMsk@M4|D4HqMbBTuM7 zGiqpSoyQFq!aF`YRFE)gWNTH$4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ico new file mode 100644 index 0000000000000000000000000000000000000000..4965832f2c9b0605eaa189b7c7fb11124d24e48a GIT binary patch literal 15086 zcmeHOOH5Q(7(R0cc?bh2AT>N@1PWL!LLfZKyG5c!MTHoP7_p!sBz0k$?pjS;^lmgJ zU6^i~bWuZYHL)9$wuvEKm~qo~(5=Lvx5&Hv;?X#m}i|`yaGY4gX+&b>tew;gcnRQA1kp zBbm04SRuuE{Hn+&1wk%&g;?wja_Is#1gKoFlI7f`Gt}X*-nsMO30b_J@)EFNhzd1QM zdH&qFb9PVqQOx@clvc#KAu}^GrN`q5oP(8>m4UOcp`k&xwzkTio*p?kI4BPtIwX%B zJN69cGsm=x90<;Wmh-bs>43F}ro$}Of@8)4KHndLiR$nW?*{Rl72JPUqRr3ta6e#A z%DTEbi9N}+xPtd1juj8;(CJt3r9NOgb>KTuK|z7!JB_KsFW3(pBN4oh&M&}Nb$Ee2 z$-arA6a)CdsPj`M#1DS>fqj#KF%0q?w50GN4YbmMZIoF{e1yTR=4ablqXHBB2!`wM z1M1ke9+<);|AI;f=2^F1;G6Wfpql?1d5D4rMr?#f(=hkoH)U`6Gb)#xDLjoKjp)1;Js@2Iy5yk zMXUqj+gyk1i0yLjWS|3sM2-1ECc;MAz<4t0P53%7se$$+5Ex`L5TQO_MMXXi04UDIU+3*7Ez&X|mj9cFYBXqM{M;mw_ zpw>azP*qjMyNSD4hh)XZt$gqf8f?eRSFX8VQ4Y+H3jAtvyTrXr`qHAD6`m;aYmH2zOhJC~_*AuT} zvUxC38|JYN94i(05R)dVKgUQF$}#cxV7xZ4FULqFCNX*Forhgp*yr6;DsIk=ub0Hv zpk2L{9Q&|uI^b<6@i(Y+iSxeO_n**4nRLc`P!3ld5jL=nZRw6;DEJ*1z6Pvg+eW|$lnnjO zjd|8>6l{i~UxI244CGn2kK@cJ|#ecwgSyt&HKA2)z zrOO{op^o*- + + + + + + + + + + + + + diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/app/layout.js b/test/e2e/app-dir/metadata-icons-parallel-routes/app/layout.js new file mode 100644 index 0000000000000..a3a86a5ca1e12 --- /dev/null +++ b/test/e2e/app-dir/metadata-icons-parallel-routes/app/layout.js @@ -0,0 +1,7 @@ +export default function Root({ children }) { + return ( + + {children} + + ) +} diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/app/page.js b/test/e2e/app-dir/metadata-icons-parallel-routes/app/page.js new file mode 100644 index 0000000000000..f9cb981736359 --- /dev/null +++ b/test/e2e/app-dir/metadata-icons-parallel-routes/app/page.js @@ -0,0 +1,3 @@ +export default function Page() { + return

page

+} diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/app/test.png b/test/e2e/app-dir/metadata-icons-parallel-routes/app/test.png new file mode 100644 index 0000000000000000000000000000000000000000..7cbc1d26733614b83dcc25b9cfcd5e06dffb147c GIT binary patch literal 1661 zcmV-@27>vCP)LUUqAigYBsiM4LpbwXrcM#DLg%sv zqYV7atJ2!&9+4a}Z~>mx*QQG8O{j2%jKM&gp$l9QGmOhXo1ym@G1NiGAj_1lhANDV z1!S4frxq9i3di1^l$}15Gz3>C_2kBUE^I5>7jp>X5wdo&Pd!2a6f5GP)GgXa3QSQ5 zJ0>bk8Vt=;h$f0RQz4ot-b{sPqIfeEqKV?oREQ=HW#$APi4kKst#JY0qCFI7KO!;| z-{Dx5|6)LB*iF*ATe1cl&QpkEr#`hqi_TA*>5v*DyuQX9nwI%PlNUBUM=lW0iy@%% zB^BF?>xE4!QsG#Qk#JB|Zt7m}4cuf9&Sc^>nhincOJ6g{>L6IPUat?vOi^vN=pG%= zK#)fFriX`z1CgewsCHXKz1WKmEejx6qkEB3>Y%mGjoj^a`R9__Z&8YtD2$*QSF6?G zlq}0cwcn!FRXGQOH@cIk`fMagBI@t3C`Ai25VWzK_5A#7HS(IOas~u%Y$wfTvqK&8 z`CQcBV^O1VSn-#r$_`Ey)bSA>M>05=GHK|=D&vNW5yX)MHLMsk@M4|D4HqMbBTuM7 zGiqpSoyQFq!aF`YRFE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ata-icons-parallel-routes/metadata-icons-parallel-routes.test.ts new file mode 100644 index 0000000000000..3436c4666aad2 --- /dev/null +++ b/test/e2e/app-dir/metadata-icons-parallel-routes/metadata-icons-parallel-routes.test.ts @@ -0,0 +1,14 @@ +import { nextTestSetup } from 'e2e-utils' + +describe('app-dir - metadata-icons-parallel-routes', () => { + const { next } = nextTestSetup({ + files: __dirname, + }) + + it('should present favicon with other icons when parallel routes are presented', async () => { + const $ = await next.render$('/') + expect($('link[type="image/x-icon"]').length).toBe(1) + expect($('link[type="image/svg+xml"]').length).toBe(1) + expect($('link[rel="apple-touch-icon"]').length).toBe(1) + }) +}) From c7a5386488b37527571470af54fb164d005ab273 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Fri, 9 Aug 2024 12:24:58 +0200 Subject: [PATCH 2/7] filter out parallel routes --- .../next/src/lib/metadata/resolve-metadata.ts | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/next/src/lib/metadata/resolve-metadata.ts b/packages/next/src/lib/metadata/resolve-metadata.ts index c81ec901e91ba..02f3902373750 100644 --- a/packages/next/src/lib/metadata/resolve-metadata.ts +++ b/packages/next/src/lib/metadata/resolve-metadata.ts @@ -104,15 +104,15 @@ function mergeStaticMetadata( if (!staticFilesMetadata) return const { icon, apple, openGraph, twitter, manifest } = staticFilesMetadata - if ((icon || apple) && !target.icons) { - target.icons = { - icon: icon || [], - apple: apple || [], - } - } - if (isLastSegment) { - // file based metadata is specified and current level metadata icons is not specified - if (target.icons) { + if (icon || apple) { + if (isLastSegment) { + if (!target.icons) { + target.icons = { + icon: [], + apple: [], + } + } + // file based metadata is specified and current level metadata icons is not specified if (icon) { target.icons.icon.unshift(...icon) } @@ -540,16 +540,20 @@ export async function resolveMetadataItems({ for (const key in parallelRoutes) { const childTree = parallelRoutes[key] - await resolveMetadataItems({ - tree: childTree, - metadataItems, - errorMetadataItem, - parentParams: currentParams, - treePrefix: currentTreePrefix, - searchParams, - getDynamicParamFromSegment, - errorConvention, - }) + // Only collect the metadata for normal routes, skip the parallel routes. + const isChildrenRouteKey = key === 'children' + if (isChildrenRouteKey) { + await resolveMetadataItems({ + tree: childTree, + metadataItems, + errorMetadataItem, + parentParams: currentParams, + treePrefix: currentTreePrefix, + searchParams, + getDynamicParamFromSegment, + errorConvention, + }) + } } if (Object.keys(parallelRoutes).length === 0 && errorConvention) { From ef5cb15024fc7aba6abc786bea22f62fcad1c7b4 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Fri, 9 Aug 2024 14:23:39 +0200 Subject: [PATCH 3/7] update the latest left node static icons --- .../next/src/lib/metadata/resolve-metadata.ts | 80 +++++++++++-------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/packages/next/src/lib/metadata/resolve-metadata.ts b/packages/next/src/lib/metadata/resolve-metadata.ts index 02f3902373750..8c51f3f62bd34 100644 --- a/packages/next/src/lib/metadata/resolve-metadata.ts +++ b/packages/next/src/lib/metadata/resolve-metadata.ts @@ -16,6 +16,7 @@ import type { LoaderTree } from '../../server/lib/app-dir-module' import type { AbsoluteTemplateString, IconDescriptor, + ResolvedIcons, } from './types/metadata-types' import type { ParsedUrlQuery } from 'querystring' import type { StaticMetadata } from './types/icons' @@ -49,6 +50,8 @@ import { ResolveMetadataSpan } from '../../server/lib/trace/constants' import { PAGE_SEGMENT_KEY } from '../../shared/lib/segment' import * as Log from '../../build/output/log' +type StaticIcons = Pick + type MetadataResolver = ( parent: ResolvingMetadata ) => Metadata | Promise @@ -99,27 +102,15 @@ function mergeStaticMetadata( staticFilesMetadata: StaticMetadata, metadataContext: MetadataContext, titleTemplates: TitleTemplates, - isLastSegment: boolean + leafSegmentStaticIcons: StaticIcons ) { if (!staticFilesMetadata) return const { icon, apple, openGraph, twitter, manifest } = staticFilesMetadata + // Keep updating the static icons in the most leaf node if (icon || apple) { - if (isLastSegment) { - if (!target.icons) { - target.icons = { - icon: [], - apple: [], - } - } - // file based metadata is specified and current level metadata icons is not specified - if (icon) { - target.icons.icon.unshift(...icon) - } - if (apple) { - target.icons.apple.unshift(...apple) - } - } + leafSegmentStaticIcons.icon = icon || [] + leafSegmentStaticIcons.apple = apple || [] } // file based metadata is specified and current level metadata twitter.images is not specified @@ -158,7 +149,7 @@ function mergeMetadata({ titleTemplates, metadataContext, buildState, - isLastSegment, + leafSegmentStaticIcons, }: { source: Metadata | null target: ResolvedMetadata @@ -166,7 +157,7 @@ function mergeMetadata({ titleTemplates: TitleTemplates metadataContext: MetadataContext buildState: BuildState - isLastSegment: boolean + leafSegmentStaticIcons: StaticIcons }): void { // If there's override metadata, prefer it otherwise fallback to the default metadata. const metadataBase = @@ -290,7 +281,7 @@ function mergeMetadata({ staticFilesMetadata, metadataContext, titleTemplates, - isLastSegment + leafSegmentStaticIcons ) } @@ -540,20 +531,16 @@ export async function resolveMetadataItems({ for (const key in parallelRoutes) { const childTree = parallelRoutes[key] - // Only collect the metadata for normal routes, skip the parallel routes. - const isChildrenRouteKey = key === 'children' - if (isChildrenRouteKey) { - await resolveMetadataItems({ - tree: childTree, - metadataItems, - errorMetadataItem, - parentParams: currentParams, - treePrefix: currentTreePrefix, - searchParams, - getDynamicParamFromSegment, - errorConvention, - }) - } + await resolveMetadataItems({ + tree: childTree, + metadataItems, + errorMetadataItem, + parentParams: currentParams, + treePrefix: currentTreePrefix, + searchParams, + getDynamicParamFromSegment, + errorConvention, + }) } if (Object.keys(parallelRoutes).length === 0 && errorConvention) { @@ -778,6 +765,13 @@ export async function accumulateMetadata( } let favicon + + // Collect the static icons in the most leaf node, + // since we don't collect all the static metadata icons in the parent segments. + const leafSegmentStaticIcons = { + icon: [], + apple: [], + } for (let i = 0; i < metadataItems.length; i++) { const staticFilesMetadata = metadataItems[i][1] @@ -804,7 +798,7 @@ export async function accumulateMetadata( staticFilesMetadata, titleTemplates, buildState, - isLastSegment: i === metadataItems.length - 1, + leafSegmentStaticIcons, }) // If the layout is the same layer with page, skip the leaf layout and leaf page @@ -818,6 +812,24 @@ export async function accumulateMetadata( } } + if ( + leafSegmentStaticIcons.icon.length > 0 || + leafSegmentStaticIcons.apple.length > 0 + ) { + if (!resolvedMetadata.icons) { + resolvedMetadata.icons = { + icon: [], + apple: [], + } + } + if (leafSegmentStaticIcons.icon.length > 0) { + resolvedMetadata.icons.icon.unshift(...leafSegmentStaticIcons.icon) + } + if (leafSegmentStaticIcons.apple.length > 0) { + resolvedMetadata.icons.apple.unshift(...leafSegmentStaticIcons.apple) + } + } + // Only log warnings if there are any, and only once after the metadata resolving process is finished if (buildState.warnings.size > 0) { for (const warning of buildState.warnings) { From 335bfbc3ff826fa6c24d43a7c3388b6c4ccad9f7 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Fri, 9 Aug 2024 14:39:44 +0200 Subject: [PATCH 4/7] fix override case --- packages/next/src/lib/metadata/resolve-metadata.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/next/src/lib/metadata/resolve-metadata.ts b/packages/next/src/lib/metadata/resolve-metadata.ts index 8c51f3f62bd34..a41e44d2c87e5 100644 --- a/packages/next/src/lib/metadata/resolve-metadata.ts +++ b/packages/next/src/lib/metadata/resolve-metadata.ts @@ -821,12 +821,12 @@ export async function accumulateMetadata( icon: [], apple: [], } - } - if (leafSegmentStaticIcons.icon.length > 0) { - resolvedMetadata.icons.icon.unshift(...leafSegmentStaticIcons.icon) - } - if (leafSegmentStaticIcons.apple.length > 0) { - resolvedMetadata.icons.apple.unshift(...leafSegmentStaticIcons.apple) + if (leafSegmentStaticIcons.icon.length > 0) { + resolvedMetadata.icons.icon.unshift(...leafSegmentStaticIcons.icon) + } + if (leafSegmentStaticIcons.apple.length > 0) { + resolvedMetadata.icons.apple.unshift(...leafSegmentStaticIcons.apple) + } } } From ee7439bc5bdb25cc52cd3c0a81edb8f20fa50554 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Fri, 9 Aug 2024 16:37:25 +0200 Subject: [PATCH 5/7] test: use actual paralell route stub --- .../metadata-icons-parallel-routes/app/@modal/blank.txt | 1 - .../metadata-icons-parallel-routes/app/@modal/default.js | 3 +++ .../app-dir/metadata-icons-parallel-routes/app/layout.js | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) delete mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/blank.txt create mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/default.js diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/blank.txt b/test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/blank.txt deleted file mode 100644 index b4de6870aeb01..0000000000000 --- a/test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/blank.txt +++ /dev/null @@ -1 +0,0 @@ -This file is to mark the parallel route @modal existence diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/default.js b/test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/default.js new file mode 100644 index 0000000000000..a40457174b47f --- /dev/null +++ b/test/e2e/app-dir/metadata-icons-parallel-routes/app/@modal/default.js @@ -0,0 +1,3 @@ +export default function Modal() { + return

modal

+} diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/app/layout.js b/test/e2e/app-dir/metadata-icons-parallel-routes/app/layout.js index a3a86a5ca1e12..d0fba92eee19e 100644 --- a/test/e2e/app-dir/metadata-icons-parallel-routes/app/layout.js +++ b/test/e2e/app-dir/metadata-icons-parallel-routes/app/layout.js @@ -1,7 +1,10 @@ -export default function Root({ children }) { +export default function Root({ children, modal }) { return ( - {children} + + {modal} + {children} + ) } From 20a6826bc2b9c9598e778f647752728018941f4d Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Aug 2024 16:59:23 +0200 Subject: [PATCH 6/7] override when both presented, inherit when parent present --- .../next/src/lib/metadata/resolve-metadata.ts | 9 ++++++--- .../app/nested/icon.png | Bin 0 -> 1661 bytes .../app/nested/page.js | 3 +++ .../metadata-icons-parallel-routes.test.ts | 10 ++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/app/nested/icon.png create mode 100644 test/e2e/app-dir/metadata-icons-parallel-routes/app/nested/page.js diff --git a/packages/next/src/lib/metadata/resolve-metadata.ts b/packages/next/src/lib/metadata/resolve-metadata.ts index a41e44d2c87e5..59cf33be3672d 100644 --- a/packages/next/src/lib/metadata/resolve-metadata.ts +++ b/packages/next/src/lib/metadata/resolve-metadata.ts @@ -108,9 +108,12 @@ function mergeStaticMetadata( const { icon, apple, openGraph, twitter, manifest } = staticFilesMetadata // Keep updating the static icons in the most leaf node - if (icon || apple) { - leafSegmentStaticIcons.icon = icon || [] - leafSegmentStaticIcons.apple = apple || [] + + if (icon) { + leafSegmentStaticIcons.icon = icon + } + if (apple) { + leafSegmentStaticIcons.apple = apple } // file based metadata is specified and current level metadata twitter.images is not specified diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/app/nested/icon.png b/test/e2e/app-dir/metadata-icons-parallel-routes/app/nested/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..7cbc1d26733614b83dcc25b9cfcd5e06dffb147c GIT binary patch literal 1661 zcmV-@27>vCP)LUUqAigYBsiM4LpbwXrcM#DLg%sv zqYV7atJ2!&9+4a}Z~>mx*QQG8O{j2%jKM&gp$l9QGmOhXo1ym@G1NiGAj_1lhANDV z1!S4frxq9i3di1^l$}15Gz3>C_2kBUE^I5>7jp>X5wdo&Pd!2a6f5GP)GgXa3QSQ5 zJ0>bk8Vt=;h$f0RQz4ot-b{sPqIfeEqKV?oREQ=HW#$APi4kKst#JY0qCFI7KO!;| z-{Dx5|6)LB*iF*ATe1cl&QpkEr#`hqi_TA*>5v*DyuQX9nwI%PlNUBUM=lW0iy@%% zB^BF?>xE4!QsG#Qk#JB|Zt7m}4cuf9&Sc^>nhincOJ6g{>L6IPUat?vOi^vN=pG%= zK#)fFriX`z1CgewsCHXKz1WKmEejx6qkEB3>Y%mGjoj^a`R9__Z&8YtD2$*QSF6?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tb zLI9GCJcrIr)06Ejj%H5^Da-fl@pVe)w$P_yyD7FJr+j_}po~WmWUki$00000NkvXX Hu0mjfdKc_u literal 0 HcmV?d00001 diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/app/nested/page.js b/test/e2e/app-dir/metadata-icons-parallel-routes/app/nested/page.js new file mode 100644 index 0000000000000..f9cb981736359 --- /dev/null +++ b/test/e2e/app-dir/metadata-icons-parallel-routes/app/nested/page.js @@ -0,0 +1,3 @@ +export default function Page() { + return

page

+} diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/metadata-icons-parallel-routes.test.ts b/test/e2e/app-dir/metadata-icons-parallel-routes/metadata-icons-parallel-routes.test.ts index 3436c4666aad2..a6d5607424764 100644 --- a/test/e2e/app-dir/metadata-icons-parallel-routes/metadata-icons-parallel-routes.test.ts +++ b/test/e2e/app-dir/metadata-icons-parallel-routes/metadata-icons-parallel-routes.test.ts @@ -11,4 +11,14 @@ describe('app-dir - metadata-icons-parallel-routes', () => { expect($('link[type="image/svg+xml"]').length).toBe(1) expect($('link[rel="apple-touch-icon"]').length).toBe(1) }) + + it('should override parent icon when both static icon presented', async () => { + const $ = await next.render$('/nested') + expect($('link[rel="icon"][type="image/png"]').length).toBe(1) + }) + + it('should inherit parent apple icon when child does not present but parent contain static apple icon', async () => { + const $ = await next.render$('/nested') + expect($('link[rel="apple-touch-icon"][type="image/png"]').length).toBe(1) + }) }) From 8798648bd0f5fb2667762f198026621e28d365c4 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Aug 2024 18:53:14 +0200 Subject: [PATCH 7/7] add test for favicon --- .../metadata-icons-parallel-routes.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/app-dir/metadata-icons-parallel-routes/metadata-icons-parallel-routes.test.ts b/test/e2e/app-dir/metadata-icons-parallel-routes/metadata-icons-parallel-routes.test.ts index a6d5607424764..1ebd0b77b5885 100644 --- a/test/e2e/app-dir/metadata-icons-parallel-routes/metadata-icons-parallel-routes.test.ts +++ b/test/e2e/app-dir/metadata-icons-parallel-routes/metadata-icons-parallel-routes.test.ts @@ -14,6 +14,7 @@ describe('app-dir - metadata-icons-parallel-routes', () => { it('should override parent icon when both static icon presented', async () => { const $ = await next.render$('/nested') + expect($('link[type="image/x-icon"]').length).toBe(1) expect($('link[rel="icon"][type="image/png"]').length).toBe(1) })