Skip to content

Ensure setAssetPrefix updates config instance #82160

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 1 commit into from
Jul 29, 2025
Merged

Conversation

ijjk
Copy link
Member

@ijjk ijjk commented Jul 29, 2025

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 16:45
@@ -1652,7 +1652,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

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 nextConfig.assetPrefix instead of renderOpts.assetPrefix, but other parts of the codebase still expect renderOpts.assetPrefix to be available, causing asset prefix to not work correctly.

View Details

Analysis

The change on line 1655 modified setAssetPrefix to update this.nextConfig.assetPrefix instead of this.renderOpts.assetPrefix. However, there are still two locations in the codebase that depend on renderOpts.assetPrefix:

  1. packages/next/src/server/async-storage/work-store.ts line 129: assetPrefix: renderOpts?.assetPrefix || '',
  2. packages/next/src/server/post-process.ts line 45: publicPath: \${renderOpts.assetPrefix}/_next/`,`

Both RenderOptsPartial interfaces in render.tsx and app-render/types.ts define assetPrefix?: string as an expected property. When setAssetPrefix is called during server initialization, the asset prefix will be stored in nextConfig but the code expecting it in renderOpts will receive undefined, potentially causing incorrect asset URLs or broken CSS optimization.


Recommendation

The setAssetPrefix method should update both locations to maintain consistency. Change line 1655 to:

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

Alternatively, if the intention is to only store it in nextConfig, then the code in work-store.ts and post-process.ts should be updated to read from nextConfig.assetPrefix instead of renderOpts.assetPrefix.

Copy link
Member Author

Choose a reason for hiding this comment

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

The above referenced renderOpts.assetPrefix usage is derived from the new handlers interface which is not from the base-server renderOpts instance. This will be cleared up while deleting base-server code.

@@ -1652,7 +1652,7 @@ export default abstract class Server<
): Promise<void>

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

Choose a reason for hiding this comment

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

We're still using renderOpts.assetPrefix here, do we still need to update the renderOpts.assetPrefix as well?

publicPath: `${renderOpts.assetPrefix}/_next/`,

Copy link
Member Author

Choose a reason for hiding this comment

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

@ijjk ijjk enabled auto-merge (squash) July 29, 2025 17:10
@ijjk ijjk merged commit 541902e into canary Jul 29, 2025
287 of 289 checks passed
@ijjk ijjk deleted the ijjk/fix-set-asset-prefix branch July 29, 2025 17:12
ijjk added a commit that referenced this pull request Jul 29, 2025
This ensures we update `nextConfig.assetPrefix` instead of `renderOpts`
as we aren't relying on `renderOpts` for these values anymore.

Closes: #82150
ijjk added a commit that referenced this pull request Jul 29, 2025
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.

Asset prefix is not normalized after upgrade to 15.4.1
2 participants