Skip to content

Fix/service worker offline fallback#5875

Open
DhyaniKavya wants to merge 3 commits intosugarlabs:masterfrom
DhyaniKavya:fix/service-worker-offline-fallback
Open

Fix/service worker offline fallback#5875
DhyaniKavya wants to merge 3 commits intosugarlabs:masterfrom
DhyaniKavya:fix/service-worker-offline-fallback

Conversation

@DhyaniKavya
Copy link
Contributor

issue : #5874

Problem:-
The service worker references an offlineFallbackPage variable when handling failed network requests:
=> const fallbackResponse = await caches.match(offlineFallbackPage);

However, offlineFallbackPage is only declared in a lint hint comment:
=> /* global offlineFallbackPage */

and is never defined at runtime. This can lead to a ReferenceError when the service worker attempts to serve a fallback response during offline conditions.
-Offline navigation may fail silently
-Users may see a blank page when offline
-PWA reliability is degraded

Solution:-
-This PR defines the fallback page variable to ensure the service worker can safely return a cached response when offline.
-defines offlineFallbackPage in sw.js
-uses an existing cached resource (./index.html) as fallback
-preserves existing fetch handler logic
-prevents runtime errors during offline fallback

Changes Made:-
-File modified:
->sw.js

  • defined offlineFallbackPage constant
  • ensured fallback resource matches precached file

ESLint: ✅ no lint errors
Tests: ⚠️ pre-existing failures on master (unrelated to this change)

Impact:-
-Prevents runtime errors in offline mode
-Improves Progressive Web App reliability
-Ensures graceful fallback when offline
-No functional or behavioral regressions

Notes:-
This change is intentionally minimal and non-breaking. It defines the expected fallback variable while preserving existing service worker logic and caching behavior.

Happy to refine further if maintainers prefer a dedicated offline page in the future.

@github-actions
Copy link
Contributor

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

palette.test.js
logo.test.js
logoconstants.test.js

1 similar comment
@github-actions
Copy link
Contributor

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

palette.test.js
logo.test.js
logoconstants.test.js

@vyagh
Copy link
Contributor

vyagh commented Feb 23, 2026

pre-existing jest failures??

@Chaitu7032
Copy link
Contributor

Chaitu7032 commented Feb 23, 2026

I think they are mostly reference and type errors .

@DhyaniKavya
Copy link
Contributor Author

DhyaniKavya commented Feb 23, 2026

@omsuneri The failing Jest tests appear to be pre-existing and reproducible on the current master branch.
This PR only defines the offlineFallbackPage constant in sw.js and does not touch logic covered by these tests.

@DhyaniKavya DhyaniKavya force-pushed the fix/service-worker-offline-fallback branch from 5baead0 to e61ead5 Compare February 25, 2026 05:03
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@DhyaniKavya
Copy link
Contributor Author

@omsuneri @walterbender Rebased the branch successfully and all tests are passing now . Please review the changes, if anything needs change, i am open to address it. Thankyou.

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.

3 participants