Repository navigation
fix: prepend assetsDir to bare CSS filenames in dynamicLoadingCss - #750
Open
jeff-ofobrukweta wants to merge 1 commit into
Open
jeff-ofobrukweta wants to merge 1 commit into
jeff-ofobrukweta wants to merge 1 commit into
Conversation
dynamicLoadingCss() reads build.assetsDir into an `assetsDir` variable but never used it when composing the stylesheet href for an exposed module's CSS -- it joined `base` straight onto the bare CSS filename (the runtime array is always populated with basename()'d entries, see expose-production.ts:225 and :264), dropping the assets directory the file is actually emitted into. Every request for a federated module's CSS then 404s in production whenever build.assetsDir differs from the project root (e.g. any non-default assetsDir, or a nested one). Only prepend assetsDir when cssPath has no path separator, so already -qualified paths (e.g. CDN-hosted CSS) are left untouched.
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.
Summary
dynamicLoadingCss()(the runtime helper injected intoremoteEntry.jsfor exposed modules) readsbuild.assetsDirinto anassetsDirvariable, but never actually uses it when composing the stylesheet<link>href for an exposed module's CSS. It joinsbasestraight onto the bare CSS filename, dropping the assets directory the file is actually emitted into.The CSS filenames fed into this array are always bare filenames (no path segments) — see
basename(cssBundle.fileName)at expose-production.ts:225 and :264 — so wheneverbuild.assetsDiris anything other than the project root (i.e. basically always, since Vite defaults it to"assets"), every request for a federated module's CSS 404s in production.Fix
Prepend
assetsDirtocssPathbefore it's cleaned/joined into the href, but only whencssPathhas no/in it, so any already-qualified path (e.g. an absolute/CDN-hosted CSS URL) is left untouched.Verification
build.assetsDir, every federated screen rendered completely unstyled with CSS requests 404ing; all resolved after this fix.pnpm --filter @originjs/vite-plugin-federation run buildsucceeds and the generateddist/index.js/dist/index.mjsoutput the corrected href-composition logic.This is a small, narrowly-scoped one-line-of-logic fix to a real production bug in the current release (1.4.1) with no newer version available.