Skip to content

fix: use absolute base href for SPA routing#277

Merged
fank merged 1 commit intomainfrom
fix/spa-base-href
Mar 1, 2026
Merged

fix: use absolute base href for SPA routing#277
fank merged 1 commit intomainfrom
fix/spa-base-href

Conversation

@fank
Copy link
Member

@fank fank commented Mar 1, 2026

Summary

  • Removes the special case that converted <base href="/" /> to <base href="./" /> when prefixURL is empty
  • Fixes blank page on reload when navigating to nested SPA routes like /recording/135/...

Problem

When reloading a page at a nested route (e.g. /recording/135/MP_COOP_m05_20260228_195209), the browser resolved relative asset paths against the current URL path:

  • ./assets/index.js/recording/135/assets/index.js (404)

This happened because the server injected <base href="./" /> (relative) instead of <base href="/" /> (absolute).

Test plan

  • Rebuild and deploy Docker image
  • Navigate to root / — assets load correctly
  • Navigate to /recording/<id>/<name> — page renders
  • Reload on /recording/<id>/<name> — page still renders (was broken before)
  • Verify with a non-root prefixURL (e.g. /ocap/) that assets still resolve correctly

When prefixURL is empty, the server injected <base href="./" /> (relative).
On nested SPA routes like /recording/135/..., the browser resolved asset
paths relative to the current URL, e.g. /recording/135/assets/index.js
instead of /assets/index.js, causing a blank page on reload.

Remove the special case that converted "/" to "./" so the base href is
always absolute.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue in Single Page Applications (SPAs) where reloading a nested route would result in a blank page due to incorrect asset loading. The change ensures that the injected '' is always an absolute path, preventing browsers from misinterpreting relative asset URLs against the current nested route. This guarantees that all assets load correctly, improving the reliability of SPA routing.

Highlights

  • Base href handling: Removed the special case that converted '' to '' when 'prefixURL' was empty, ensuring absolute paths are consistently used.
  • SPA Routing Fix: Fixed blank page issues on reload when navigating to nested SPA routes by ensuring the base href is always absolute, preventing incorrect asset path resolution.
Changelog
  • internal/server/handler.go
    • Removed conditional logic that previously converted the base href from an absolute path ('/') to a relative path ('./') when the prefix was the root.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a bug in the Single-Page Application routing where asset paths were resolved incorrectly on nested routes. The change removes logic that converted an absolute base href of / to a relative ./. By ensuring the base href is always absolute (/ when no prefix is given), this fix correctly resolves asset paths from the root of the domain, preventing 404 errors on page reloads. The change is confined to the intended logic and appears correct.

@github-actions
Copy link

github-actions bot commented Mar 1, 2026

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/OCAP2/web/internal/server 93.95% (-0.01%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/OCAP2/web/internal/server/handler.go 96.71% (-0.03%) 213 (-2) 206 (-2) 7 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

@fank fank merged commit 05ae9f3 into main Mar 1, 2026
2 checks passed
@fank fank deleted the fix/spa-base-href branch March 1, 2026 00:09
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