Skip to content

initialCanonicalUrl is not taking into account basePath from config #59971

@zlwaterfield

Description

@zlwaterfield

Link to the code that reproduces this issue

https://github.com/zlwaterfield/initial-canonical-url-bug

To Reproduce

  1. Create a Next.js app that uses a basePath (for example '/g/`) and the app router (or look at example repo)
  2. Create and load a page in the application (/path/testing-page in example repo)
  3. Inspect the page and find the script with self.__next_f.push(....
  4. Find the initialCanonicalUrl and 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/A

Which 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions