Skip to content

fix(build): use correct base for chunk import map - #23365

Closed
vaibhavmashal wants to merge 2 commits into
vitejs:mainfrom
vaibhavmashal:fix-chunk-import-map-base
Closed

fix(build): use correct base for chunk import map#23365
vaibhavmashal wants to merge 2 commits into
vitejs:mainfrom
vaibhavmashal:fix-chunk-import-map-base

Conversation

@vaibhavmashal

Copy link
Copy Markdown

Fixes #23350. The issue drops module preload dependency lists when base is not /. This changes \getImportMapBaseUrl\ to return \options.base\ instead of /\ when \chunkImportMap.baseUrl\ is missing.

Copilot AI lite review requested due to automatic review settings August 25, 2026 18:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vaibhavmashal

Copy link
Copy Markdown
Author

Here is a detailed explanation of what was done in this PR:

The Problem

When \�uild.chunkImportMap\ is enabled and \�ase\ is not /, the module preload dependency lists get dropped (__vite__mapDeps\ is absent). This happens because Vite injected one \�aseUrl\ into
olldown, but when reading it back, it fell back to /\ since the user's
olldownOptions\ (which it read) lacked the \�aseUrl. As a result, the preload markers didn't work and CSS wasn't requested for lazily imported chunks.

The Fix

In \packages/vite/src/node/plugins/html.ts, the function \getImportMapBaseUrl\ was updated to read from \options.base\ instead of falling back blindly to /.

\\ s
function getImportMapBaseUrl(
options: ResolvedEnvironmentOptions & Pick<ResolvedConfig, 'base'>,
): string {
const chunkImportMap =
options.build.rolldownOptions.experimental?.chunkImportMap
if (typeof chunkImportMap === 'object' && chunkImportMap.baseUrl) {
return chunkImportMap.baseUrl
}
return options.base ?? '/' // Now respects the base if present
}
\\

By changing this one line, __vite__mapDeps\ is preserved properly, the CSS gets requested, and the mapped key reverts to using the stable ID as expected.

@github-actions github-actions Bot added the bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR label Aug 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically flagged as likely to be created by a bot, LLM, or agent, and will be automatically closed. These contributions harm the maintenance of the project. Please read our AI policy for more information.

If you believe this is a mistake, please reply to this comment and we will review it.

@github-actions github-actions Bot closed this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build.chunkImportMap drops module preload dependency lists when base is not /

2 participants