Repository navigation
Force correct MIME types for UI assets on Windows (fixes unstyled UI) - #309
zwanski-start wants to merge 1 commit into
Conversation
Windows registry mappings can make Python's mimetypes report .css/.js/.svg as text/plain or similar, so StaticFiles serves the built UI with the wrong Content-Type and browsers drop styles/scripts. Register the correct types explicitly before mounting /assets, replacing the partial .js-only fix that lived as an import side effect in routers/settings.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🔍 QA report: ✅ PassedTester: Ken (cubefarm agent, in a fresh session) · Round: 1 · Author: Dennis The PR forces correct MIME types for every asset the UI build produces, and the server applies them before mounting the static assets. With a simulated broken Windows registry (.css/.js → text/plain, .svg → octet-stream), master serves the CSS as text/plain and vite.svg as application/octet-stream; with this PR they come back as text/css and image/svg+xml, and the page loads fully styled with no console errors. Lint, build and tests show no regressions: the pre-existing pytest and mypy failures are identical on master. Not tested on real Windows, so the fix is verified against the most likely cause of the issue, not the reporter's machine.
🧪 Commands run
No browser screenshots were taken in this round. Posted by cubefarm · merges automatically once GitHub's checks pass |
Closes #37
Problem
On Windows, Python's
mimetypesmodule reads extension → type mappings from the registry (HKEY_CLASSES_ROOT). Third-party software often rewrites these, e.g..css/.js→text/plain. Starlette'sStaticFiles/FileResponseusemimetypes.guess_type, so the built UI gets served with the wrongContent-Type, and browsers then ignore the styles, scripts, SVGs or fonts.The repo already had a fix, but it only covered
.jsand only ran as an import side effect ofserver/routers/settings.py. CSS, SVG and fonts were not covered.Change
server/utils/mime_types.pywithregister_static_mime_types(). It forces the correct types for every asset type the Vite build produces (.css,.js,.mjs,.svg,.json,.map, fonts, images,.wasm).server/main.pycalls it right before mounting/assetsand the SPA fallback..js-only hack fromrouters/settings.py.test_mime_types.py: fakes a corrupted registry (.css/.js→text/plain,.svg→application/octet-stream), then checks bothguess_typeand the headers an actualStaticFilesmount sends.Verification
pytest test_mime_types.py test_ws_security.py→ 13 passed;ruff checkclean.ui/dist/index.html:.js→text/javascript,.css→text/css,/vite.svg→image/svg+xml.--primaryresolves.Assumptions
Content-Typeofindex-*.css).🤖 Generated with Claude Code