fix(frontend): use absolute base path so nested SPA routes load assets#291
Conversation
Vite was configured with `base: './'` to (claimed) support a sub-path mount like `/healarr/`. In practice this breaks every nested route: visiting /scans/1 makes the browser resolve `./assets/index.js` as `/scans/assets/index.js`, the SPA fallback returns index.html for that path, and the browser refuses the import on MIME-type grounds: Refused to apply style from 'https://healarr.yi.se/scans/assets/index-...css' because its MIME type ('text/html') is not a supported stylesheet MIME type The 'works at any base path' promise was already broken by SPA routing semantics anyway — a real sub-path mount needs a build-time env var (vite `base: process.env.BASE_PATH`) plus server-side index.html base-href rewriting, not a static './'. Switch to `base: '/'`. Nested routes now load assets from /assets/* regardless of current URL. Sub-path mount is no longer silently broken — it's explicitly out of scope.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Vite configuration base path is updated from ChangesVite SPA Base Path Configuration
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Problem
Visiting any nested route (`/scans/1`, `/corruptions`, etc.) produces a blank page with this console error:
Root cause
`vite.config.ts` set `base: './'` (relative paths). When the browser is at `/scans/1` it resolves `./assets/foo.js` as `/scans/assets/foo.js`. The Go SPA fallback returns `index.html` for any unknown path, so the asset request gets HTML back, the browser rejects the import on MIME type, and React never boots.
The comment claimed this was for `/healarr/` sub-path support, but that scenario was already broken — sub-path mount needs a build-time env var and server-side base-href rewrite, not a static `./`.
Fix
Switch to `base: '/'`. Built `index.html` now references `/assets/*` absolutely; nested routes load identically to the root route.
If sub-path mount is ever wanted, it's a separate feature (vite `base: process.env.BASE_PATH` + a server-side template rewrite), and the comment now says so explicitly.
Test plan
Summary by CodeRabbit