Skip to content

Commit

Permalink
Allow override icon rel (#49194)
Browse files Browse the repository at this point in the history
Fixes #48392

When passing down `Array<IconDescriptor>`, it should allow overriding `rel` prop of icon instead of always picking the default one
fix NEXT-1085
  • Loading branch information
huozhi authored May 4, 2023
1 parent 7fd97b8 commit bf09c65
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/lib/metadata/generate/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function IconDescriptorLink({ icon }: { icon: IconDescriptor }) {

function IconLink({ rel, icon }: { rel?: string; icon: Icon }) {
if (typeof icon === 'object' && !(icon instanceof URL)) {
if (rel) icon.rel = rel
if (!icon.rel && rel) icon.rel = rel
return <IconDescriptorLink icon={icon} />
} else {
const href = icon.toString()
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/app-dir/metadata/app/icons/descriptor/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ export default function page() {

export const metadata = {
icons: {
icon: [{ url: '/icon.png' }, new URL('/icon.png', 'https://example.com')],
icon: [
{ url: '/icon.png' },
new URL('/icon.png', 'https://example.com'),
{ url: '/icon2.png', rel: 'apple-touch-icon' }, // override icon rel
],
shortcut: ['/shortcut-icon.png'],
apple: [
{ url: '/apple-icon.png' },
Expand Down
1 change: 1 addition & 0 deletions test/e2e/app-dir/metadata/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ createNextDescribe(
'https://example.com/icon.png',
])
await checkLink(browser, 'apple-touch-icon', [
'/icon2.png',
'/apple-icon.png',
'/apple-icon-x3.png',
])
Expand Down

0 comments on commit bf09c65

Please sign in to comment.