Skip to content

fix(core): allow assetPrefix to be an empty string#6971

Merged
chenjiahan merged 11 commits intoweb-infra-dev:mainfrom
xun082:fix/environment-assetprefix-override
Feb 8, 2026
Merged

fix(core): allow assetPrefix to be an empty string#6971
chenjiahan merged 11 commits intoweb-infra-dev:mainfrom
xun082:fix/environment-assetprefix-override

Conversation

@xun082
Copy link
Contributor

@xun082 xun082 commented Jan 14, 2026

Summary

Fixes an issue where dev.assetPrefix configuration leaks to Node environment in multi-environment setup, causing Worker imports to fail with "Cannot find module" errors.

Problem:

  • In development mode, when global dev.assetPrefix is set (e.g., /1.0.0/), environment-specific output.assetPrefix is ignored
  • Node environment cannot use relative paths (empty string) for Worker and dynamic imports
  • This causes runtime errors: Error: Cannot find module '/1.0.0/src_server_worker_ts.js'

Solution:

  • Environment-specific output.assetPrefix now takes priority over global dev.assetPrefix in dev mode
  • Only applies when explicitly set to non-default values (preserves existing behavior)
  • Empty string assetPrefix is preserved without formatting to enable relative paths for node targets

Changes:

  • Modified getPublicPath() function in packages/core/src/plugins/output.ts
  • Added priority logic: environment-specific output.assetPrefix (if non-default) → dev.assetPrefix → default
  • Preserved empty string values without trailing slash formatting

Related Links

Closes #6539

Checklist

  • Tests updated (or not required). - All existing unit tests pass (311 tests)
  • Documentation updated (or not required). - Code comments added to explain the behavior

@netlify
Copy link

netlify bot commented Jan 14, 2026

Deploy Preview for rsbuild-v2 ready!

Name Link
🔨 Latest commit c8c78c7
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild-v2/deploys/6969aed92e6f480008d68d31
😎 Deploy Preview https://deploy-preview-6971--rsbuild-v2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @xun082, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue in development mode where a global dev.assetPrefix could override environment-specific output.assetPrefix settings, leading to module resolution failures in Node.js environments, particularly for dynamic and Worker imports. The solution introduces refined logic to prioritize explicit environment-specific output.assetPrefix configurations and ensures that empty string assetPrefix values are correctly handled to facilitate relative paths, thereby preventing runtime errors and improving the robustness of multi-environment setups.

Highlights

  • Asset Prefix Priority in Dev Mode: Environment-specific output.assetPrefix now takes priority over the global dev.assetPrefix when in development mode, but only if it's explicitly set to a non-default value.
  • Node Environment Module Resolution Fix: This change resolves an issue where dev.assetPrefix configuration would incorrectly leak to the Node environment in multi-environment setups, causing 'Cannot find module' errors for Worker and dynamic imports.
  • Relative Path Preservation: Empty string values for assetPrefix are now preserved without formatting, which is essential for enabling correct relative paths for Node targets.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes an issue where dev.assetPrefix would override an environment-specific output.assetPrefix in development mode, which is crucial for multi-environment setups, especially for Node.js targets that require relative asset paths. The changes in getPublicPath correctly prioritize the environment-specific configuration and also ensure that an empty assetPrefix is preserved. My review includes a suggestion to refactor a related utility function for better long-term maintainability.

Copy link
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

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

I'm concerned this change will break SSR hydration: #6539 (comment)

@xun082
Copy link
Contributor Author

xun082 commented Jan 16, 2026

I'm concerned this change will break SSR hydration: #6539 (comment)

Thanks for the concern. I've fixed it: when server.base is set, server targets now use it to match the client's public path for SSR hydration, while still preserving empty string for worker_threads when server.base is not set.

Copy link
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

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

This PR seems to break down into two parts:

  1. Allowing assetPrefix to be an empty string. This change makes sense to me, and I’d be happy to see this part merged first.
  2. Automatically adjusting assetPrefix for the Node target. This part feels a bit too complex, and I find it difficult to clearly explain the behavior in the documentation, so I'm a bit cautious about moving forward with this change.

@xun082
Copy link
Contributor Author

xun082 commented Jan 16, 2026

This PR seems to break down into two parts:

  1. Allowing assetPrefix to be an empty string. This change makes sense to me, and I’d be happy to see this part merged first.
  2. Automatically adjusting assetPrefix for the Node target. This part feels a bit too complex, and I find it difficult to clearly explain the behavior in the documentation, so I'm a bit cautious about moving forward with this change.

Thanks for the feedback! I’ll simplify the changes by keeping the first part (allowing an empty assetPrefix) and removing the automatic adjustment for Node targets. However, there are E2E test failures related to Node target manifest paths — something I haven’t worked with in E2E tests before, so I’m unfamiliar with this error. Do you have any insight into the cause? Should we update the tests to match the new behavior, or do you suggest a different approach for handling manifest paths for Node targets?

@chenjiahan
Copy link
Member

I will check the failed E2E cases and try to fix them

@chenjiahan chenjiahan changed the title fix(core): respect environment-specific output.assetPrefix in dev mode fix(core): allow assetPrefix to be an empty string Feb 8, 2026
@chenjiahan chenjiahan merged commit 895b356 into web-infra-dev:main Feb 8, 2026
6 checks passed
@chenjiahan
Copy link
Member

Thank you! I've merged the first part changes

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.

[Bug]: dev.assetPrefix leaks to Node env in multi enviroment setup

2 participants