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

viewport setting in metadata is not working correctly #63592

Closed
hi-paul opened this issue Mar 22, 2024 · 5 comments
Closed

viewport setting in metadata is not working correctly #63592

hi-paul opened this issue Mar 22, 2024 · 5 comments
Labels
bug Issue was opened via the bug report template. locked

Comments

@hi-paul
Copy link

hi-paul commented Mar 22, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/priceless-rgb-2hcyms?file=%2Fapp%2Flayout.tsx&workspaceId=12540e31-6959-44ce-a050-2ec2eabe3bda

To Reproduce

Add code to root layout.tsx

export const metadata = {
  viewport: { width: 1920 }
}

Current vs. Expected behavior

current: <meta name="viewport" content="width=device-width, initial-scale=1" />

expected: <meta name="viewport" content="width=1920" />

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000
Binaries:
  Node: 20.11.0
  npm: 10.2.4
  Yarn: 1.22.19
  pnpm: 8.14.1
Relevant Packages:
  next: 13.5.6
  eslint-config-next: 13.5.6
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 4.9.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, Metadata (metadata, generateMetadata, next/head)

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

No response

@hi-paul hi-paul added the bug Issue was opened via the bug report template. label Mar 22, 2024
@hi-paul
Copy link
Author

hi-paul commented Mar 22, 2024

I recently upgraded vercel version and didn't realize that the viewport for metadata was deprecated. Thanks for letting me know🙏 @ttaerrim

When I applied it as you suggested, it looks like <meta name="viewport" content="width=1920, initial-scale=1">, but can't I remove the ,initial-scale=1?

@ttaerrim
Copy link

Sorry, I deleted my comment by mistake.

try to add code to root layout.tsx

export const viewport: Viewport = {
  width: 1920
}

But I don't know how to initialize viewport tag to none.

@devjiwonchoi
Copy link
Member

Hi, initial-scale set to 1 will not harm since it is the default value.
Since the default value is mapped internally, you cannot explicitly remove it from your source.

export function createDefaultViewport(): ResolvedViewport {
return {
// name=viewport
width: 'device-width',
initialScale: 1,
// visual metadata
themeColor: null,
colorScheme: null,
}
}

Also, it is recommended to follow the Codemods so that you don't need to explicitly export viewport.

ref: https://nextjs.org/docs/app/building-your-application/upgrading/codemods#use-viewport-export

@hi-paul
Copy link
Author

hi-paul commented Mar 25, 2024

Actually, what I'm working on now is to show the desktop in 1920 width on the mobile screen. Before upgrading nextjs, it was <meta name="viewport" content="width=1920" /> and it worked as I wanted, but now it doesn't work when it's set to <meta name="viewport content="width=1920, initial-scale=1" />.

The default value of initial-scale is 1, but I figured that its presence had an impact, so I set initial-scale to -1 and it worked fine.

Thank you for your kind explanation and help in resolving the issue.

@hi-paul hi-paul closed this as completed Mar 25, 2024
Copy link
Contributor

github-actions bot commented Apr 8, 2024

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Apr 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

No branches or pull requests

3 participants