Repository navigation
Fix unstyled UI on Windows: pin MIME types for web assets - #256
zwanski-start wants to merge 1 commit into
Conversation
Python's mimetypes reads the Windows registry, which third-party software often rewrites so .css (or .js) maps to text/plain. Starlette then serves the built stylesheet with the wrong Content-Type and browsers refuse it, leaving the UI unstyled. Only .js was previously overridden (in the settings router); register all web asset types centrally in main.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🔍 QA report: ✅ PassedTester: Ada (cubefarm agent, in a fresh session) · Round: 1 · Author: Barbara I reproduced issue #37 on master by simulating a Windows registry that maps .css/.js to text/plain: the stylesheet was served as text/plain, Chromium loaded it with 0 rules and the UI rendered unstyled with no console errors, exactly as reported. On this PR the same setup serves text/css and text/javascript, the stylesheet loads (322 rules) and the UI is fully styled with a clean console. ruff, the security suites, the UI build and lint pass. The mypy errors (25) and pytest failures (21, all in test_devserver_security.py) are identical on master, and both new tests fail when the fix is disabled.
🧪 Commands run
No browser screenshots were taken in this round. Posted by cubefarm · merges automatically once GitHub's checks pass |
Adaptation: AutoForgeAI#317 (issue AutoForgeAI#49) is covered by this change: its .css/.mjs/.svg/.json/.wasm lines are all in WEB_MIME_TYPES, and its importlib.reload test is dropped. Integrates AutoForgeAI#256 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeH26pcsqoxPb3CDs8g1VN
Closes #37
Problem
On Windows, Python's
mimetypesmodule seeds its table from the registry (HKEY_CLASSES_ROOT\.css→Content Type). Editors and other installed software often rewrite these entries (e.g..css→text/plain). Starlette'sStaticFiles/FileResponseusemimetypes.guess_type(), so the built stylesheet comes back with the wrongContent-Type. The browser refuses to apply it, and the UI renders with no colors, as in the issue screenshot. The JS bundle still runs because.jswas already overridden, only for that one extension, inserver/routers/settings.py.Change
server/utils/mime_types.pywithregister_web_mime_types(). It sets the correct type for every asset extension Vite emits (css, js, mjs, json, map, html, svg, png, ico, webp, woff, woff2, wasm).server/main.pycalls it before mounting the static files..js-only override from the settings router, where it had no reason to live.Verification
test_mime_types.pymaps.css/.jstotext/plain, the way a broken registry does, then checks thatregister_web_mime_types()restores the right types and that aStaticFilesmount servestext/css/text/javascript.ruff check .,python test_security.py,pytest test_mime_types.py test_ws_security.py,npm run buildandnpm run lintall pass. Lint gives 6 warnings and 0 errors; I left the warnings alone.server.main:appon port 5443 with.css/.jsmapped totext/plainbefore startup.curl -Ishowedtext/cssandtext/javascript. In Playwright the stylesheet loaded (322 rules) and the page was fully styled.Assumptions
mimetypesproblem that the existing.jsfix was written for.zwanski-start/autoforgebecause the account has only read access to the upstream repo.🤖 Generated with Claude Code