fix: infer publicPath "auto" for a relative Vite base (base: "./")#893
Merged
gioboa merged 1 commit intoJul 10, 2026
Merged
Conversation
e609632 to
6753a17
Compare
When a remote is built with a relative Vite base (`base: "./"` or "."),
`resolvePublicPath` returned the literal relative value (via
`ensureTrailingSlash("./")` -> "./") and emitted it as the manifest's
`metaData.publicPath`.
A relative publicPath is not usable by the Module Federation runtime: it
resolves remote chunks relative to the host document instead of the remote
entry, so consuming a remote from a different origin/path fails to load its
assets. A relative base is precisely the case where the runtime should infer
the location from the remote entry script, i.e. webpack's "auto".
Treat a relative base ("./" or ".") as "auto", matching the existing behavior
for an unset base.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
6753a17 to
fed7fe8
Compare
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
A relative Vite base (
base: "./") exists so a build can be hosted under any folder without knowing that folder at build time — you deploy the same output to/,/app/,/some/deep/path/, etc., and every asset URL is resolved relative to wherever the entry actually loaded from. That's the whole point of"./": "relative to whatever folder I choose to host under." Vite documents exactly this value:./(for embedded deployment).The Module Federation
publicPathshould follow the same principle: it should be determined automatically at runtime from the location the remote entry was loaded from. Instead, when a remote is built withbase: "./"(and no explicitpublicPath), the generatedmf-manifest.jsonbakes in a literal"./":A literal
"./"publicPathdefeats the purpose.publicPathtells the MF runtime where to load the remote's chunks from, and"./"gets resolved relative to the host document — i.e. the host site's root (or whatever page is consuming the remote) — not the folder the remote entry was actually served from. So the moment the remote is hosted under a subfolder, or consumed from a host on a different path/origin, its shared/exposed chunks resolve to the wrong location and fail to load.A relative base is precisely the case where the location must be inferred from the remote entry script at runtime — webpack's
"auto"— rather than pinned to the consumer's root.Root cause
resolvePublicPathinsrc/utils/pathNormalization.ts:For
base: "./",originalBaseis truthy so the'auto'branch is skipped, andensureTrailingSlash("./")returns the literal"./". A relative base falls through to the literal branch instead of being treated as "infer at runtime".Fix
Treat a relative base the same as an unset base — return
"auto":The check matches exactly
"./"because that is the only relative value Vite ever produces for a resolvedconfig.base. Vite's config resolution mapsbase: "./"(andbase: "") to exactly"./"for a client build, and normalizes any other"."-prefixed base (e.g.".","../") to"/"with a warning ("The value can only be an absolute URL,./, or an empty string"). So a broader check likestartsWith('./')or a=== '.'branch would be dead code.Absolute bases (
/foo/) and full-URL bases (https://cdn/) are unaffected. The dev (serve) path is unaffected because it already passes nooriginalBaseand returns"auto"early (and Vite resolves a relative base to"/"in serve anyway).Tests
Added unit coverage for
resolvePublicPathinsrc/utils/__tests__/pathNormalization.test.ts, including the relative-base cases ("./"and"."→"auto") plus characterization tests for the explicit-publicPath,"auto"-as-unset, unset-base, and absolute-base paths.pnpm test→ all unit tests pass (642)pnpm typecheck→ cleanoxfmt --check src→ clean