Skip to content

fix: serve module .mjs chunks and CSS via MapStaticAssets#94

Merged
antosubash merged 1 commit intomainfrom
feature/tender-heisenberg
Apr 8, 2026
Merged

fix: serve module .mjs chunks and CSS via MapStaticAssets#94
antosubash merged 1 commit intomainfrom
feature/tender-heisenberg

Conversation

@antosubash
Copy link
Copy Markdown
Owner

Changes

Static Asset Configuration

  • Register .mjs (ES module chunks from Vite code-splitting) in Directory.Build.props so MapStaticAssets includes them in the manifest
  • Remove fallback UseStaticFiles middleware that was masking the core issue

Module CSS Injection

  • Add BuildModuleCssLinks() to HtmlFileInertiaPageRenderer to auto-discover and inject <link> tags for module CSS files at startup
  • Replace <!--MODULE_CSS_LINKS--> placeholder in index.html
  • Remove runtime CSS loading logic from resolve-page.ts (now handled at render time)

Build & Deployment

  • Update .dockerignore to exclude Vite output directories and .vite caches to prevent stale artifacts
  • Add docker-build-nocache and docker-clean-run Makefile targets
  • Expand clean target to remove module wwwroot outputs, ClientApp bundle, and Vite caches
  • Add clean-run target for development workflow

Dependencies

  • Update rolldown and @oxc-project/types to rc.13
  • Update vite to 8.0.7

Production was hitting two categories of asset 404s:

1. Code-split .mjs chunks from module Vite builds (e.g. Users/Login)
   were silently dropped from the StaticWebAssets endpoint manifest
   because .mjs is not in the SDK's default content-type mappings. A
   previous UseStaticFiles fallback couldn't reach RCL _content/ paths,
   so the browser got a hard 404 and login broke.

   Fix: register .mjs as text/javascript via StaticWebAssetContentTypeMapping
   in Directory.Build.props. MapStaticAssets now emits an endpoint per
   .mjs file with fingerprinting and compression for free. The fallback
   middleware in SimpleModuleHostExtensions is removed.

2. resolve-page.ts speculatively injected a <link> tag for every
   navigated module, which 404'd for every module without CSS and
   polluted the console with strict-MIME warnings.

   Fix: discover module CSS server-side. HtmlFileInertiaPageRenderer
   walks WebRootFileProvider(\"_content\") once at startup and injects
   <link> tags for every module that ships its own {assembly}.css into
   a new <!--MODULE_CSS_LINKS--> placeholder in index.html. The client
   resolver no longer touches CSS at all.

Supporting changes:
- .dockerignore excludes module wwwroot build outputs and .vite caches
  so stale local artifacts can't be baked into images.
- Makefile clean now scrubs Vite outputs (emptyOutDir is false, so Vite
  never clears them itself), plus new clean-run, docker-build-nocache,
  and docker-clean-run convenience targets.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying simplemodule-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: f30dd91
Status: ✅  Deploy successful!
Preview URL: https://5b990a45.simplemodule-website.pages.dev
Branch Preview URL: https://feature-tender-heisenberg.simplemodule-website.pages.dev

View logs

@antosubash antosubash merged commit 34a006b into main Apr 8, 2026
5 checks passed
@antosubash antosubash deleted the feature/tender-heisenberg branch April 8, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant