fix: serve SPA shell for deep links on GitHub Pages - #203
Conversation
GitHub Pages has no rewrite rule for client-side routes, so loading or reloading a route such as /overview or /contributors returned the default "File not found" page instead of the app. Emit 404.html as a copy of index.html at build time. Pages serves it for any unmatched path, the app boots, and React Router resolves the route from window.location with the URL preserved.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughThe Vite configuration adds a build plugin that copies the generated ChangesSPA deep-link fallback
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: Poem
✨ Finishing Touches🧪 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 |
Addressed Issues:
Fixes #202
What was wrong
App.jsxusesBrowserRouterwith real paths, but GitHub Pages serves static files only and has no rewrite rule mapping unknown paths back to the app shell. So a direct visit to — or a reload of —/overview,/contributors,/governance, etc. requested a file that does not exist on disk and Pages returned its own "File not found" page. The app never booted.This also meant the Share button produced links that 404'd for the recipient, and
sitemap.xmlentries were uncrawlable.The fix
One build-time plugin in
vite.config.jsthat emits404.htmlas a copy ofindex.html.GitHub Pages serves
404.htmlfor any unmatched path, so the app boots and React Router resolves the route fromwindow.location. The URL is preserved — there is no redirect and no flash, which is why this is preferred over the older?redirect=query-string workaround.No runtime code changed, no dependency added, no change to the deploy workflow. Local
npm run devandnpm run previewalready had this behaviour via Vite's dev server; this closes the gap for the production Pages build.Verification
npm run buildnpm testdist/404.htmlemittedcmp dist/404.html dist/index.htmlGET /overviewunder GitHub Pages semanticsid="root"), React Router resolves the routevite.config.jsonlyVerified with a local static server replicating GitHub Pages' behaviour (serve the file if it exists, otherwise serve
404.html), then loadedhttp://localhost:8099/overviewin a real browser — the OrgExplorer shell renders instead of the Pages 404.Additional Notes:
CONTRIBUTING.mdasks contributors to runnpm run lint, butpackage.jsonhas nolintscript (available:dev,build,preview,test,coverage). Happy to fix that separately if useful.Checklist
AI assistance was used to diagnose and implement this change. The root cause was reproduced on the live site, the fix was verified locally against a server replicating GitHub Pages' static-serving behaviour, and the full build and test suite were run before submitting.
Summary by CodeRabbit