Skip to content

[backport] Ensure setAssetPrefix updates config instance #82165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2025

Conversation

ijjk
Copy link
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 ztanner and huozhi July 29, 2025 17:14
@@ -1707,7 +1707,7 @@ export default abstract class Server<
): Promise<void>

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

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant