Skip to content

Conversation

@Jeevankumar-s
Copy link

What?

Fix metadata icon URLs generated with Turbopack to correctly respect basePath.

Why?

When using Turbopack with a configured basePath, metadata icons (favicon, apple icons, etc.)
are generated without the basePath prefix, resulting in broken icon URLs.
This works correctly with Webpack but fails with Turbopack.

How?

  • Apply basePath to root-relative metadata icon URLs during metadata resolution
  • Skip absolute URLs and prevent double-prefixing
  • Match Webpack behavior without changing public APIs

Fixes #87422

@nextjs-bot
Copy link
Collaborator

nextjs-bot commented Dec 20, 2025

Allow CI Workflow Run

  • approve CI run for commit: 28dc767

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

The createMetadataContext function doesn't include the basePath property that the metadata icon resolution code expects, causing the basePath to never be applied to icon URLs.

View Details
📝 Patch Details
diff --git a/packages/next/src/lib/metadata/metadata-context.tsx b/packages/next/src/lib/metadata/metadata-context.tsx
index 7f65e6ac8c..9d7c347eb3 100644
--- a/packages/next/src/lib/metadata/metadata-context.tsx
+++ b/packages/next/src/lib/metadata/metadata-context.tsx
@@ -1,11 +1,12 @@
 import type { AppRenderContext } from '../../server/app-render/app-render'
-import type { MetadataContext } from './types/resolvers'
+import type { MetadataContext, MetadataContextWithBasePath } from './types/resolvers'
 
 export function createMetadataContext(
   renderOpts: AppRenderContext['renderOpts']
-): MetadataContext {
+): MetadataContextWithBasePath {
   return {
     trailingSlash: renderOpts.trailingSlash,
     isStaticMetadataRouteFile: false,
+    basePath: renderOpts.basePath,
   }
 }

Analysis

Missing basePath property in createMetadataContext causes icon basePath to never be applied

What fails: The createMetadataContext() function does not include the basePath property from renderOpts, causing ctx.basePath to be undefined in applyBasePathToIcons(), which prevents icon URLs from being prefixed with the configured basePath.

How to reproduce:

// In resolve-metadata.ts, when processing metadata with icons and a configured basePath:
const metadataContext = createMetadataContext(ctx.renderOpts)  // ctx.renderOpts.basePath = '/my-app'
// ...later in mergeMetadata()
const ctx = metadataContext as MetadataContextWithBasePath
applyBasePathToIcons(resolvedIcons, ctx.basePath)  // ctx.basePath is undefined

Result: Icon URLs are not prefixed with the basePath. For example, /favicon.ico remains /favicon.ico instead of becoming /my-app/favicon.ico.

Expected: The createMetadataContext() function should include the basePath from renderOpts in the returned context object, allowing applyBasePathToIcons() to correctly apply the basePath prefix to icon URLs.

Files affected: packages/next/src/lib/metadata/metadata-context.tsx

Fix on Vercel

@Jeevankumar-s Jeevankumar-s marked this pull request as draft December 21, 2025 06:59
@Jeevankumar-s Jeevankumar-s marked this pull request as ready for review December 21, 2025 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Turbopack] Generate icons using code missing basePath config with turbopack

2 participants