-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Closed
Labels
Description
Link to the code that reproduces this issue
https://github.com/zlwaterfield/initial-canonical-url-bug
To Reproduce
- Create a Next.js app that uses a basePath (for example '/g/`) and the app router (or look at example repo)
- Create and load a page in the application (/path/testing-page in example repo)
- Inspect the page and find the script with
self.__next_f.push(.... - Find the
initialCanonicalUrland it will be missing the base path (path).
Also see #53274 for more information.
Current vs. Expected behavior
The initialCanonicalUrl should have the basePath included in it.
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 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000
Binaries:
Node: 18.17.0
npm: 9.6.7
Yarn: 1.22.19
pnpm: 8.12.1
Relevant Packages:
next: 14.0.4
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: N/A
Next.js Config:
output: N/AWhich area(s) are affected? (Select all that apply)
App Router, Metadata (metadata, generateMetadata, next/head), Script optimization (next/script)
Additional context
This is causing issues with SEO because crawlers see the URL and think it's a valid URL. From what I gather, there is currently no way to properly set it. We are getting 404s from this in the Google Search Console.
My only idea to fix it right now is to rewrite the URL in our Cloudflare worker until a fix is shipped in Next.js
tombennet, jakubkustra-tomtom, philipheinser, cameronsb, tonyjara and 6 more