Skip to content

fix(web): fix push notification click 404 on GitHub Pages#322

Merged
tiann merged 1 commit intotiann:mainfrom
pppobear:fix/pwa-notification-404-github-pages
Mar 20, 2026
Merged

fix(web): fix push notification click 404 on GitHub Pages#322
tiann merged 1 commit intotiann:mainfrom
pppobear:fix/pwa-notification-404-github-pages

Conversation

@pppobear
Copy link
Contributor

Fixes #321

Problem

When running in relay mode (hapi hub --relay), the web app is served from app.hapi.run (GitHub Pages). Tapping a push notification opens /sessions/:id in 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 notificationclick handler in sw.ts calls clients.openWindow('/sessions/:id'). The relative URL resolves to https://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 in sessionStorage, then redirects to /
  • web/src/lib/spaRedirect.tsrestoreSpaRedirect() reads sessionStorage before router init and calls window.history.replaceState with the stored path
  • web/src/main.tsx — Calls restoreSpaRedirect() 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.ts covering:

  • Restores stored path via replaceState
  • Cleans up sessionStorage after restore
  • No-op when no redirect is stored
  • Preserves query string and hash
  • storeSpaRedirect captures full path including search and hash

All 43 web tests pass.

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>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Review mode: initial — No issues found. Residual risk/testing gap: Tests not run; SPA redirect relies on GitHub Pages 404 + sessionStorage behavior.\n\nHAPI Bot

@tiann tiann merged commit f539f10 into tiann:main Mar 20, 2026
2 checks passed
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.

Push notification click leads to 404 on GitHub Pages (relay mode)

2 participants