fix(web): fix push notification click 404 on GitHub Pages#322
Merged
tiann merged 1 commit intotiann:mainfrom Mar 20, 2026
Merged
fix(web): fix push notification click 404 on GitHub Pages#322tiann merged 1 commit intotiann:mainfrom
tiann merged 1 commit intotiann:mainfrom
Conversation
When the hub runs in relay mode, the web app is served from app.hapi.run (GitHub Pages). Clicking a push notification opens /sessions/:id in a new tab, but GitHub Pages returns 404 for any path that doesn't have a corresponding file. Add public/404.html that stores the intended path in sessionStorage and redirects to /. On bootstrap, restore the path via replaceState before TanStack Router initializes, so the router sees the correct URL without a server round-trip. Also extract the redirect logic into spaRedirect.ts with unit tests. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #321
Problem
When running in relay mode (
hapi hub --relay), the web app is served fromapp.hapi.run(GitHub Pages). Tapping a push notification opens/sessions/:idin a new tab. GitHub Pages has no file at that path, so it returns 404 Not Found instead of serving the SPA.This only affects relay mode. The hub's own static server (non-relay) has a proper SPA fallback and works correctly.
Root Cause
The
notificationclickhandler insw.tscallsclients.openWindow('/sessions/:id'). The relative URL resolves tohttps://app.hapi.run/sessions/:id. GitHub Pages serves 404 for any path that doesn't correspond to a real file.Solution
Standard GitHub Pages SPA routing workaround (no changes to service worker or notification payload needed):
web/public/404.html— Stores the intended path insessionStorage, then redirects to/web/src/lib/spaRedirect.ts—restoreSpaRedirect()reads sessionStorage before router init and callswindow.history.replaceStatewith the stored pathweb/src/main.tsx— CallsrestoreSpaRedirect()on bootstrap (skipped in Telegram environment which uses memory history)TanStack Router initializes at the correct URL without any server round-trip, so the right session is rendered immediately.
Tests
Added unit tests in
web/src/lib/spaRedirect.test.tscovering:replaceStatesessionStorageafter restorestoreSpaRedirectcaptures full path including search and hashAll 43 web tests pass.