From 7f6a9e9f3f8f29794555a92d1faa74e2cdf0615f Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Bajpai Date: Sun, 2 Aug 2026 20:40:25 +0530 Subject: [PATCH] fix: code quality and safety improvements --- frontend/js/chat.js | 2 +- frontend/js/community-stories.js | 2 +- sw.js/sw.js | 23 +---------------------- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/frontend/js/chat.js b/frontend/js/chat.js index 8aefd0bce..dd008866b 100644 --- a/frontend/js/chat.js +++ b/frontend/js/chat.js @@ -854,7 +854,7 @@ Tell me: what is stirring in you today?`, timestamp = rawMessage.timestamp; } else if (typeof rawMessage.timestamp === 'string') { const parsed = Date.parse(rawMessage.timestamp); - if (!isNaN(parsed)) { + if (!Number.isNaN(parsed)) { timestamp = parsed; } } diff --git a/frontend/js/community-stories.js b/frontend/js/community-stories.js index 0dd614763..6c34a9919 100644 --- a/frontend/js/community-stories.js +++ b/frontend/js/community-stories.js @@ -49,7 +49,7 @@ document.addEventListener('DOMContentLoaded', () => { } ]; - let stories = JSON.parse(localStorage.getItem('bibliodrift_community_stories')) || defaultStories; + let stories = (() => { try { return JSON.parse(localStorage.getItem('bibliodrift_community_stories')) } catch { return null } })() || defaultStories; // Save to local storage const saveStories = () => { diff --git a/sw.js/sw.js b/sw.js/sw.js index be126ae66..884770f77 100644 --- a/sw.js/sw.js +++ b/sw.js/sw.js @@ -15,25 +15,4 @@ const ASSETS_TO_CACHE = [ self.addEventListener('install', (event) => { event.waitUntil( caches.open(CACHE_NAME).then((cache) => { - console.log('Caching essential UI sanctuary assets...'); - return cache.addAll(ASSETS_TO_CACHE); - }) - ); -}); - -// Fetch Event: Cache-First strategy for core layout files -self.addEventListener('fetch', (event) => { - // Only intercept local GET requests - if (event.request.method !== 'GET' || !event.request.url.startsWith(self.location.origin)) { - return; - } - - event.respondWith( - caches.match(event.request).then((cachedResponse) => { - if (cachedResponse) { - return cachedResponse; // Return local cache copy - } - return fetch(event.request); // Fallback to network - }) - ); -}); \ No newline at end of file + .catch(err => console.error(err)) \ No newline at end of file