Skip to content

Commit

Permalink
core(viewport-meta): include initial-scale value condition (#15394)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianaixba authored Aug 21, 2023
1 parent 958177d commit cd09b63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/computed/viewport-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ class ViewportMeta {
}

const viewportProps = parsedProps.validProperties;
const isMobileOptimized = Boolean(viewportProps.width || viewportProps['initial-scale']);
const initialScale = Number(viewportProps['initial-scale']);

if (!isNaN(initialScale) && initialScale < 1) {
return {
hasViewportTag: true,
isMobileOptimized: false,
parserWarnings: warnings,
};
}

const isMobileOptimized = Boolean(viewportProps.width || initialScale);

return {
hasViewportTag: true,
Expand Down
8 changes: 8 additions & 0 deletions core/test/computed/viewport-meta-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ describe('ViewportMeta computed artifact', () => {
assert.equal(parserWarnings[1], 'Invalid values found: {"initial-scale":"microscopic"}');
});

// eslint-disable-next-line max-len
it('is not mobile optimized when a viewport contains an initial-scale value lower than 1', async () => {
const viewport = 'width=device-width, initial-scale=0.9';
const {isMobileOptimized} =
await ViewportMeta.compute_(makeMetaElements(viewport));
assert.equal(isMobileOptimized, false);
});

it('is mobile optimized when a valid viewport is provided', async () => {
const viewports = [
'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1',
Expand Down

0 comments on commit cd09b63

Please sign in to comment.