vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.41k stars 27.03k forks source link

New metadataBase field (on `metadata` object) does not prepend specfied metadata base URL in head tag `href`s #53455

Open md-coops opened 1 year ago

md-coops commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.4.13-canary.9
      eslint-config-next: 13.4.12
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A

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

Metadata (metadata, generateMetadata, next/head), Static HTML Export (output: "export")

Link to the code that reproduces this issue or a replay of the bug

https://github.com/md-coops/nextJS-bug-report

To Reproduce

Run npm run build to build static export solution.

Describe the Bug

In the ./src/app/layout.tsx file, setting metadata.metadataBase = "https://custom.domain" does not append the base url to href attributes for link tags in the head tag of html pages. We can see this when generating a static export and inspecting the generated ./out/index.html.

Expected Behavior

I would expect the key of metadata.metadataBase to pre-pend the relative URLs in the href atribute in link tags in the head tag of html documents. e.g. <head><link rel="stylesheet" href="https://custom.domain/_next/static/css/25ef7fcca74b1a97.css" data-precedence="next"/></ head>

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

FlorianLeChat commented 1 year ago

I'm having exactly the same issue with the latest version at the time of writing (NextJS 14.x). Both warnings from NextJS and what the documentation says about this property are pretty confusing by the way.

image image image

Who's lying? Is it the docs which say you can use it in all fields (when in fact it doesn't work)? Or only for OpenGraph links?

tuscland commented 1 year ago

It is kind of a bummer to be forced to define metadataBase with an absolute URL for the root layout. The reason why is unclear to me.