Unverified Commit 0c6f6357 authored by Artem Zelenov's avatar Artem Zelenov Committed by GitHub

fix: remove initial-scale=1 from viewport when set to false (#76397)

Co-authored-by: 's avatarJiachi Liu <inbox@huozhi.im>
parent 3396eac7
......@@ -5,7 +5,6 @@ import type {
} from '../types/metadata-interface'
import type { ViewportLayout } from '../types/extra-types'
import React from 'react'
import { Meta, MetaFilter, MultiMeta } from './meta'
import { ViewportMetaKeys } from '../constants'
import { getOrigin } from './utils'
......@@ -20,9 +19,15 @@ function resolveViewportLayout(viewport: Viewport) {
const viewportKey = viewportKey_ as keyof ViewportLayout
if (viewportKey in viewport) {
let value = viewport[viewportKey]
if (typeof value === 'boolean') value = value ? 'yes' : 'no'
if (resolved) resolved += ', '
resolved += `${ViewportMetaKeys[viewportKey]}=${value}`
if (typeof value === 'boolean') {
value = value ? 'yes' : 'no'
} else if (!value && viewportKey === 'initialScale') {
value = undefined
}
if (value) {
if (resolved) resolved += ', '
resolved += `${ViewportMetaKeys[viewportKey]}=${value}`
}
}
}
}
......
......@@ -780,6 +780,14 @@ describe('accumulateViewport', () => {
interactiveWidget: 'overlays-content',
})
})
it('should skip viewport.initialScale if it is set undefined explicitly', async () => {
const viewport = await accumulateViewport([{ initialScale: undefined }])
expect(viewport).toMatchObject({
width: 'device-width',
initialScale: undefined,
})
})
})
describe('themeColor', () => {
......
......@@ -327,10 +327,9 @@ function mergeViewport({
target.colorScheme = source.colorScheme || null
break
default:
if (typeof source[key] !== 'undefined') {
// @ts-ignore viewport properties
target[key] = source[key]
}
// always override the target with the source
// @ts-ignore viewport properties
target[key] = source[key]
break
}
}
......
import type { Viewport } from 'next'
export default function Page() {
return <p>skip initial scale</p>
}
export const viewport: Viewport = {
initialScale: undefined,
}
......@@ -775,6 +775,14 @@ describe('app dir - metadata', () => {
'theme-color': '#000',
})
})
it('should skip initial-scale from viewport if it is set to undefined', async () => {
const browser = await next.browser('/viewport/skip-initial-scale')
const matchMultiDom = createMultiDomMatcher(browser)
await matchMultiDom('meta', 'name', 'content', {
viewport: 'width=device-width',
})
})
})
describe('react cache', () => {
......
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