-
Notifications
You must be signed in to change notification settings - Fork 29k
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
Conversation
@@ -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(/\/$/, '') : '' |
There was a problem hiding this comment.
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
:
packages/next/src/server/async-storage/work-store.ts
line 129:assetPrefix: renderOpts?.assetPrefix || '',
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
.
There was a problem hiding this comment.
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(/\/$/, '') : '' |
There was a problem hiding this comment.
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/`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ensures we update `nextConfig.assetPrefix` instead of `renderOpts` as we aren't relying on `renderOpts` for these values anymore. Closes: #82150
This ensures we update
nextConfig.assetPrefix
instead ofrenderOpts
as we aren't relying onrenderOpts
for these values anymore.Closes: #82150