Skip to content

Fix stale service worker caching causing blank screen after deployment#961

Open
abhishek-2k23 wants to merge 1 commit intostagefrom
SW-Bug
Open

Fix stale service worker caching causing blank screen after deployment#961
abhishek-2k23 wants to merge 1 commit intostagefrom
SW-Bug

Conversation

@abhishek-2k23
Copy link
Contributor

Closes #960

Description

This PR replaces the custom service worker implementation with a safer vite-plugin-pwa configuration to prevent stale HTML and JS caching issues that caused blank screens after deployment.


Problem

The previous service worker:

  • Permanently cached index.html
  • Did not refresh cache on new deployments
  • Served outdated HTML referencing deleted hashed JS files
  • Intercepted API routes unintentionally

This caused:

  • White screen after deployment
  • Failed to load module script errors
  • Required manual "Empty cache and hard reload"

Changes Made

  • Removed custom service-worker.js

  • Removed manual service worker registration

  • Implemented vite-plugin-pwa

  • Disabled automatic precaching of large JS bundles

  • Configured runtime caching:

    • NetworkFirst for navigation (HTML)
    • NetworkOnly for /api/*
    • StaleWhileRevalidate for styles
    • CacheFirst for images
  • Enabled automatic service worker updates using registerType: 'autoUpdate'


Result

  • No more stale HTML
  • No more blank screen after deployment
  • No JS precaching issues
  • No API interference
  • Safe for Vercel deployments
  • Installable PWA remains functional

Testing

  • Deployed new build
  • Verified that new deployment loads correctly without manual cache clearing
  • Confirmed no module loading errors in DevTools
  • Verified service worker is active and controlling the page

What type of PR is this? (Check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📄 Documentation Update
  • 👨‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🛠️ CI/CD

Screenshots (if applicable)

/ or index.html file not cached. Only required assets and files cached
image

Checklist

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@abhishek-2k23 abhishek-2k23 self-assigned this Feb 18, 2026
@abhishek-2k23 abhishek-2k23 added the bug Something isn't working label Feb 18, 2026
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.7.0 Service Worker caches stale index.html causing blank screen after new deployment

1 participant