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

[NEXT-1087] Next OpenGraph Image not working with basePath #49162

Closed
1 task done
josepholiveira opened this issue May 3, 2023 · 6 comments · Fixed by #49226
Closed
1 task done

[NEXT-1087] Next OpenGraph Image not working with basePath #49162

josepholiveira opened this issue May 3, 2023 · 6 comments · Fixed by #49226
Assignees
Labels
area: app App directory (appDir: true) Metadata Related to Next.js' Metadata API.

Comments

@josepholiveira
Copy link

josepholiveira commented May 3, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 21:00:41 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T8103
    Binaries:
      Node: 18.15.0
      npm: 9.5.0
      Yarn: 1.22.19
      pnpm: 8.3.1
    Relevant packages:
      next: 13.3.4
      eslint-config-next: 13.3.4
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue

https://github.com/josepholiveira/next13-opengraph-image-basepath-bug

To Reproduce

  • Clone repository
  • npm i
  • npm run dev
  • Go to page localhost:3000/test (/test is the basePath in next.config.js)
  • Inspect element or use an Metadata checker to see that the opengraph-image.jpg does not have the basePath in the beginning, so it won't ever be loaded correctly.
  • Alternatively you can just deploy and share the URL in discord or any other page, and see that the image is not embedded

Describe the Bug

When using the NextJs app folder, with the Metadata API, we can create files named opengraph-image.(jpg|jpeg|png|gif), it works like a charm but not when setting up a basePath in the next.config.js file.

Giving an example, when not using the basePath, the image is added like this to the og:image field:

http://localhost:3000/opengraph-image-1vqp9l.jpg?d41089021927a9d2

image

But when using the basePath, accessing this URL is not valid and it will not work, but when trying to access manually adding the basePath to the URL, it works:

http://localhost:3000/test/opengraph-image-1vqp9l.jpg?d41089021927a9d2

image

But NextJS is currently, despite setting up the basePath in next.config.js, not adding the basePath automatically when we use the opengraph-image.

Also, adding here, another bug is that it always considers 3000 as the port, but I was using 3001 that was another reason it didn't work locally.

image

Expected Behavior

I expected Next to automatically handle the basePath for the opengraph-image.

Which browser are you using? (if relevant)

Chrome

How are you deploying your application? (if relevant)

Vercel

NEXT-1087

@josepholiveira josepholiveira added the bug Issue was opened via the bug report template. label May 3, 2023
@github-actions github-actions bot added the area: app App directory (appDir: true) label May 3, 2023
@josepholiveira
Copy link
Author

josepholiveira commented May 4, 2023

Note: Just upgraded to NextJS 13.3.4. This is still a problem, even it being now stable.

@huozhi huozhi self-assigned this May 4, 2023
@huozhi huozhi added the Metadata Related to Next.js' Metadata API. label May 4, 2023
@huozhi
Copy link
Member

huozhi commented May 4, 2023

Thanks for reporting, will take a look! 13.4.x is not on npm yet (by the time we comment), but will def follow up to get the fix out asap in later patches 🙏

@huozhi huozhi added kind: bug and removed bug Issue was opened via the bug report template. labels May 4, 2023
@huozhi huozhi changed the title Next OpenGraph Image not working with basePath [NEXT-1087] Next OpenGraph Image not working with basePath May 4, 2023
@josepholiveira
Copy link
Author

josepholiveira commented May 4, 2023

@huozhi My mistake, now I oficially tested 13.4, and it's still a problem! :p

Thank you for taking a look!

ijjk pushed a commit that referenced this issue May 4, 2023
Fixes #49162

When user configures the `basePath` in `next.config.js`, we need to
apply it to metadata image path resolving
fix NEXT-1087
@huozhi
Copy link
Member

huozhi commented May 4, 2023

The fix is landed in 13.4.1-canary.1

@josepholiveira
Copy link
Author

Awesome, thanks for doing it so quick! @huozhi

leechenghsiu added a commit to openhci-workshop/taichi-2023 that referenced this issue May 25, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 4, 2023

This closed issue has been automatically locked because it had no new activity for a month. 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 locked as resolved and limited conversation to collaborators Jun 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) Metadata Related to Next.js' Metadata API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants