-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ui): PWA polish, smart service worker caching, and DuckDB splash screen #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
816a5bb
feat(ui): PWA icons, CSS modules, theme and layout refactor
sushruth 3738b2c
fix(ui): rewrite service worker with targeted caching strategy
sushruth c5c5b54
feat(ui): add DuckDB loading splash screen with progress tracking
sushruth f48cf6d
fix(ui): move vite triple-slash reference before imports in vite-env.…
sushruth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,75 +1,87 @@ | ||
| // Service Worker for Fossiq PWA | ||
| const CACHE_NAME = "fossiq-v1"; | ||
| const ASSETS_TO_CACHE = ["/", "/index.html"]; | ||
| // Version is updated during build process | ||
| const VERSION = "{{VERSION}}"; | ||
| const CACHE_NAME = `fossiq-v${VERSION}`; | ||
|
|
||
| // DuckDB binaries: large, essentially immutable — cache-first | ||
| const DUCKDB_PATTERN = /\/(duckdb-[^/]+\.wasm|duckdb-[^/]+\.worker\.js)$/; | ||
|
|
||
| // Vite content-hashed assets: safe to cache forever — cache-first | ||
| // Matches e.g. /assets/index-CEEKSdb3.js, /assets/index-D9aWs9Jp.css | ||
| const HASHED_ASSET_PATTERN = /\/assets\/.+-[A-Za-z0-9]{8}\.(js|css|woff2?)(\.map)?$/; | ||
|
|
||
| // Install event - cache assets | ||
| self.addEventListener("install", (event) => { | ||
| event.waitUntil( | ||
| caches.open(CACHE_NAME).then((cache) => { | ||
| return cache.addAll(ASSETS_TO_CACHE).catch(() => { | ||
| console.log("Some assets could not be cached"); | ||
| }); | ||
| }) | ||
| ); | ||
| console.log(`[SW] Installing version ${VERSION}`); | ||
| // Skip waiting so the new SW takes over immediately on next navigation | ||
| self.skipWaiting(); | ||
| }); | ||
|
|
||
| // Activate event - clean up old caches | ||
| self.addEventListener("activate", (event) => { | ||
| console.log(`[SW] Activating version ${VERSION}`); | ||
| event.waitUntil( | ||
| caches.keys().then((cacheNames) => { | ||
| return Promise.all( | ||
| cacheNames | ||
| .filter((cacheName) => cacheName !== CACHE_NAME) | ||
| .map((cacheName) => caches.delete(cacheName)) | ||
| (async () => { | ||
| const cacheNames = await caches.keys(); | ||
| await Promise.all( | ||
| cacheNames.map((name) => { | ||
| if (name !== CACHE_NAME) { | ||
| console.log(`[SW] Deleting old cache: ${name}`); | ||
| return caches.delete(name); | ||
| } | ||
| return Promise.resolve(); | ||
| }) | ||
| ); | ||
| }) | ||
| await self.clients.claim(); | ||
| })() | ||
| ); | ||
| self.clients.claim(); | ||
| }); | ||
|
|
||
| // Fetch event - serve from cache, fallback to network | ||
| self.addEventListener("fetch", (event) => { | ||
| // Skip non-GET requests | ||
| if (event.request.method !== "GET") { | ||
| return; | ||
| } | ||
| if (event.request.method !== "GET") return; | ||
| if (!event.request.url.startsWith("http")) return; | ||
|
|
||
| event.respondWith( | ||
| caches.match(event.request).then((response) => { | ||
| if (response) { | ||
| return response; | ||
| } | ||
| const { pathname } = new URL(event.request.url); | ||
|
|
||
| return fetch(event.request) | ||
| .then((response) => { | ||
| // Don't cache non-successful responses | ||
| if (!response || response.status !== 200 || response.type === "error") { | ||
| return response; | ||
| } | ||
| if (DUCKDB_PATTERN.test(pathname) || HASHED_ASSET_PATTERN.test(pathname)) { | ||
| // Cache-first: serve from cache, fetch+store on miss | ||
| event.respondWith(cacheFirst(event.request)); | ||
| } else { | ||
| // Network-first: always try network, fall back to cache if offline | ||
| event.respondWith(networkFirst(event.request)); | ||
| } | ||
| }); | ||
|
|
||
| // Only cache http and https requests | ||
| if (!event.request.url.startsWith("http")) { | ||
| return response; | ||
| } | ||
| async function cacheFirst(request) { | ||
| const cached = await caches.match(request); | ||
| if (cached) return cached; | ||
|
|
||
| // Clone the response | ||
| const responseToCache = response.clone(); | ||
| const response = await fetch(request); | ||
| if (response.ok) { | ||
| const cache = await caches.open(CACHE_NAME); | ||
| cache.put(request, response.clone()); | ||
| } | ||
| return response; | ||
| } | ||
|
|
||
| // Cache the fetched response for future use | ||
| caches.open(CACHE_NAME).then((cache) => { | ||
| cache.put(event.request, responseToCache); | ||
| }); | ||
| async function networkFirst(request) { | ||
| try { | ||
| const response = await fetch(request); | ||
| if (response.ok) { | ||
| const cache = await caches.open(CACHE_NAME); | ||
| cache.put(request, response.clone()); | ||
| } | ||
| return response; | ||
| } catch { | ||
| const cached = await caches.match(request); | ||
| if (cached) return cached; | ||
| return new Response("Service unavailable. Please check your connection.", { | ||
| status: 503, | ||
| statusText: "Service Unavailable", | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return response; | ||
| }) | ||
| .catch(() => { | ||
| // Return a fallback if both cache and network fail | ||
| return new Response( | ||
| "Service unavailable. Please check your connection.", | ||
| { status: 503, statusText: "Service Unavailable" } | ||
| ); | ||
| }); | ||
| }) | ||
| ); | ||
| self.addEventListener("message", (event) => { | ||
| if (event.data?.type === "SKIP_WAITING") { | ||
| self.skipWaiting(); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| .editorPane, | ||
| .resultsPane { | ||
| display: flex; | ||
| flex-direction: column; | ||
| overflow: hidden; | ||
| flex: 1; | ||
| min-height: 0; | ||
| } | ||
|
|
||
| .editorPane { | ||
| border-right: 1px solid var(--border-color); | ||
| } | ||
|
|
||
| .paneHeader { | ||
| padding: 0.75rem 1rem; | ||
| border-bottom: 1px solid var(--border-color); | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| gap: 1rem; | ||
| flex-shrink: 0; | ||
| background-color: var(--bg-secondary); | ||
| } | ||
|
|
||
| .paneHeaderTitle { | ||
| font-size: 0.8rem; | ||
| font-weight: 700; | ||
| margin: 0; | ||
| text-transform: uppercase; | ||
| letter-spacing: 0.8px; | ||
| color: var(--text-primary); | ||
| opacity: 0.7; | ||
| flex: 1; | ||
| } | ||
|
|
||
| .paneActions { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.5rem; | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| .editorContainer { | ||
| flex: 1; | ||
| overflow: auto; | ||
| background-color: var(--bg-primary); | ||
| border: none; | ||
| padding: 0; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On activation, the SW deletes every cache except the current
CACHE_NAME. BecauseCACHE_NAMEis versioned per build, this guarantees that large immutable assets (DuckDB WASM/worker and Vite hashed assets) will be purged and re-downloaded on every deployment, negating the “cache forever” intent and potentially hurting repeat-load performance. Consider using separate caches (e.g., a stablestaticcache for DuckDB + hashed assets, and a versionedruntimecache for network-first resources), and only clear the versioned/runtime cache on update.