Skip to content

fix(frontend): use absolute base path so nested SPA routes load assets#291

Merged
mescon merged 1 commit into
mainfrom
fix/vite-base-absolute
Jun 3, 2026
Merged

fix(frontend): use absolute base path so nested SPA routes load assets#291
mescon merged 1 commit into
mainfrom
fix/vite-base-absolute

Conversation

@mescon
Copy link
Copy Markdown
Owner

@mescon mescon commented Jun 3, 2026

Problem

Visiting any nested route (`/scans/1`, `/corruptions`, etc.) produces a blank page with this console error:

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
Failed to load module script: Expected JavaScript ... server responded with text/html

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

  • `npm run build` clean
  • Built `web/index.html` uses `<script src="/assets/...">` (absolute)
  • After deploy: `/scans/` renders, no MIME errors in console

Summary by CodeRabbit

  • Bug Fixes
    • Fixed routing configuration to properly support deep links and nested application routes.

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.
@mescon mescon merged commit 0a02ec4 into main Jun 3, 2026
0 of 2 checks passed
@mescon mescon deleted the fix/vite-base-absolute branch June 3, 2026 17:11
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: de2ea7a1-ff2c-46f3-9398-f3f21ff3c90f

📥 Commits

Reviewing files that changed from the base of the PR and between c66ec04 and 858a4cb.

📒 Files selected for processing (1)
  • frontend/vite.config.ts

📝 Walkthrough

Walkthrough

The Vite configuration base path is updated from './' (relative) to '/' (absolute) with a comment explaining how this prevents asset resolution issues in nested single-page application routes.

Changes

Vite SPA Base Path Configuration

Layer / File(s) Summary
Absolute base path configuration
frontend/vite.config.ts
Vite base property changed from relative './' to absolute '/', with explanatory comment clarifying how absolute paths correctly handle nested SPA route asset resolution and prevent deep-link failures when the HTML fallback is served.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A path once relative, now shines with light,
From './' to '/', the routes are right,
Deep links no longer stumble or fall,
Nested routes answered by one path for all,
SPA routes blessed with absolute might! 🌟

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/vite-base-absolute

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mescon mescon mentioned this pull request Jun 3, 2026
4 tasks
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