Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set sizes prop to any for svg icons #52609

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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)
Expand All @@ -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}`,
}),
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 @@ -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"]')
Expand Down