Skip to content

[backport] Ensure setAssetPrefix updates config instance #82165

Merged
ijjk merged 2 commits intonext-15-4from
ijjk/backport-assetprefix-handling
Jul 29, 2025
Merged

[backport] Ensure setAssetPrefix updates config instance #82165
ijjk merged 2 commits intonext-15-4from
ijjk/backport-assetprefix-handling

Conversation

@ijjk
Copy link
Copy Markdown
Member

@ijjk ijjk commented Jul 29, 2025

Backports #82160 to our next-15-4 release branch

This ensures we update `nextConfig.assetPrefix` instead of `renderOpts`
as we aren't relying on `renderOpts` for these values anymore.

Closes: #82150
@ijjk ijjk requested review from huozhi and ztanner July 29, 2025 17:14

public setAssetPrefix(prefix?: string): void {
this.renderOpts.assetPrefix = prefix ? prefix.replace(/\/$/, '') : ''
this.nextConfig.assetPrefix = prefix ? prefix.replace(/\/$/, '') : ''
Copy link
Copy Markdown
Contributor

@vercel vercel Bot Jul 29, 2025

Choose a reason for hiding this comment

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

The setAssetPrefix() method now sets this.nextConfig.assetPrefix instead of this.renderOpts.assetPrefix, but rendering code expects the asset prefix to be available in renderOpts.

View Details

Analysis

The change from this.renderOpts.assetPrefix = prefix to this.nextConfig.assetPrefix = prefix breaks the asset prefix functionality during rendering. Multiple parts of the rendering pipeline expect renderOpts.assetPrefix to be available:

  1. packages/next/src/server/post-process.ts:45 uses renderOpts.assetPrefix for CSS optimization
  2. packages/next/src/server/async-storage/work-store.ts:137 uses renderOpts?.assetPrefix || '' for work store setup
  3. Both the Pages and App Router RenderOptsPartial type definitions include assetPrefix?: string as an expected property

The renderOpts object is created by spreading this.renderOpts (lines 1798 and 2552), but the initial renderOpts construction (line 562+) doesn't include assetPrefix from nextConfig. The asset prefix is meant to be set dynamically via the setAssetPrefix() method, but now it's being set on the wrong object.

This will cause asset prefix functionality to fail, resulting in incorrect URLs for static assets, potentially breaking CSS optimization, and causing the work store to default to an empty asset prefix.


Recommendation

Change line 1710 back to set the asset prefix on renderOpts instead of nextConfig:

this.renderOpts.assetPrefix = prefix ? prefix.replace(/\/$/, '') : ''

If there's a need to also update nextConfig.assetPrefix for consistency, both should be set:

const normalizedPrefix = prefix ? prefix.replace(/\/$/, '') : ''
this.renderOpts.assetPrefix = normalizedPrefix
this.nextConfig.assetPrefix = normalizedPrefix

@ijjk ijjk merged commit 5bc4b36 into next-15-4 Jul 29, 2025
161 checks passed
@ijjk ijjk deleted the ijjk/backport-assetprefix-handling branch July 29, 2025 18:09
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant