Unverified Commit 76eec86a authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Set sizes prop to any for svg icons (#52609)

For `link` tag's `sizes` property, the property is defined as:

> This attribute defines the sizes of the icons for visual media contained in the resource. It must be present only if the [rel](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#rel) contains a value of icon or a non-standard type such as Apple's apple-touch-icon. It may have the following values:
`any`, meaning that the icon can be scaled to any size as it is in a vector format, like image/svg+xml.

x-ref: https://html.spec.whatwg.org/#attr-link-sizes
x-ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link (`sizes` property definition section) 

Closes #52002
Closes NEXT-133
parent 4c4bee71
......@@ -26,9 +26,9 @@ interface Options {
async function nextMetadataImageLoader(this: any, content: Buffer) {
const options: Options = this.getOptions()
const { type, segment, pageExtensions, basePath } = options
const numericSizes = type === 'twitter' || type === 'openGraph'
const { resourcePath, rootContext: context } = this
const { name: fileNameBase, ext } = path.parse(resourcePath)
const useNumericSizes = type === 'twitter' || type === 'openGraph'
let extension = ext.slice(1)
if (extension === 'jpg') {
......@@ -144,7 +144,7 @@ async function nextMetadataImageLoader(this: any, content: Buffer) {
}`
}
const imageSize = await getImageSize(
const imageSize: { width?: number; height?: number } = await getImageSize(
content,
extension as 'avif' | 'webp' | 'png' | 'jpeg'
).catch((err) => err)
......@@ -159,11 +159,11 @@ async function nextMetadataImageLoader(this: any, content: Buffer) {
...(extension in imageExtMimeTypeMap && {
type: imageExtMimeTypeMap[extension as keyof typeof imageExtMimeTypeMap],
}),
...(numericSizes
? { width: imageSize.width as number, height: imageSize.height as number }
...(useNumericSizes && imageSize.width != null && imageSize.height != null
? imageSize
: {
sizes:
extension === 'ico'
extension === 'ico' || extension === 'svg'
? 'any'
: `${imageSize.width}x${imageSize.height}`,
}),
......
......@@ -646,6 +646,7 @@ createNextDescribe(
const iconSvg = $('link[rel="icon"][type="image/svg+xml"]')
expect(iconSvg.attr('href')).toBe('/icon.svg?90699bff34adba1f')
expect(iconSvg.attr('sizes')).toBe('any')
$ = await next.render$('/basic')
const icon = $('link[rel="icon"]')
......
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