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 { ...@@ -5,7 +5,6 @@ import type {
} from '../types/metadata-interface' } from '../types/metadata-interface'
import type { ViewportLayout } from '../types/extra-types' import type { ViewportLayout } from '../types/extra-types'
import React from 'react'
import { Meta, MetaFilter, MultiMeta } from './meta' import { Meta, MetaFilter, MultiMeta } from './meta'
import { ViewportMetaKeys } from '../constants' import { ViewportMetaKeys } from '../constants'
import { getOrigin } from './utils' import { getOrigin } from './utils'
...@@ -20,9 +19,15 @@ function resolveViewportLayout(viewport: Viewport) { ...@@ -20,9 +19,15 @@ function resolveViewportLayout(viewport: Viewport) {
const viewportKey = viewportKey_ as keyof ViewportLayout const viewportKey = viewportKey_ as keyof ViewportLayout
if (viewportKey in viewport) { if (viewportKey in viewport) {
let value = viewport[viewportKey] let value = viewport[viewportKey]
if (typeof value === 'boolean') value = value ? 'yes' : 'no' if (typeof value === 'boolean') {
if (resolved) resolved += ', ' value = value ? 'yes' : 'no'
resolved += `${ViewportMetaKeys[viewportKey]}=${value}` } else if (!value && viewportKey === 'initialScale') {
value = undefined
}
if (value) {
if (resolved) resolved += ', '
resolved += `${ViewportMetaKeys[viewportKey]}=${value}`
}
} }
} }
} }
......
...@@ -780,6 +780,14 @@ describe('accumulateViewport', () => { ...@@ -780,6 +780,14 @@ describe('accumulateViewport', () => {
interactiveWidget: 'overlays-content', 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', () => { describe('themeColor', () => {
......
...@@ -327,10 +327,9 @@ function mergeViewport({ ...@@ -327,10 +327,9 @@ function mergeViewport({
target.colorScheme = source.colorScheme || null target.colorScheme = source.colorScheme || null
break break
default: default:
if (typeof source[key] !== 'undefined') { // always override the target with the source
// @ts-ignore viewport properties // @ts-ignore viewport properties
target[key] = source[key] target[key] = source[key]
}
break 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', () => { ...@@ -775,6 +775,14 @@ describe('app dir - metadata', () => {
'theme-color': '#000', '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', () => { 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