Skip to content

Commit 02d885d

Browse files
fuzzie360claude
andcommitted
fix: Stop service worker hijacking non-root paths
The CRA navigation fallback served the precached app shell for every extension-less path, so https://gpu.rocks/api/ (the API reference) and deep links like /benchmark rendered the homepage for any visitor with the service worker installed — the HashRouter then rewrote the URL to /api/#/, matching the report exactly. The site is hash-routed, so the shell is only needed at the root. Also skipWaiting so existing clients pick the fix up on next load. Fixes gpujs/gpu.js#852 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 737cf74 commit 02d885d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎service-worker.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ importScripts(
1717
"/precache-manifest.a748150979fd58f0c772c08e85930ed5.js"
1818
);
1919

20+
self.skipWaiting();
21+
2022
self.addEventListener('message', (event) => {
2123
if (event.data && event.data.type === 'SKIP_WAITING') {
2224
self.skipWaiting();
@@ -33,7 +35,12 @@ workbox.core.clientsClaim();
3335
self.__precacheManifest = [].concat(self.__precacheManifest || []);
3436
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
3537

38+
// The site is hash-routed (HashRouter), so the app shell is only ever needed
39+
// at the root. Without this whitelist the fallback swallows every extension-less
40+
// path — /api/ (the API reference) and /benchmark rendered the homepage instead
41+
// of the real page for anyone with the service worker installed.
42+
// See gpujs/gpu.js#852. Re-applied automatically by scripts/patch-sw.js.
3643
workbox.routing.registerNavigationRoute(workbox.precaching.getCacheKeyForURL("/index.html"), {
37-
44+
whitelist: [/^\/$/],
3845
blacklist: [/^\/_/,/\/[^/]+\.[^/]+$/],
3946
});

0 commit comments

Comments
 (0)