-
Notifications
You must be signed in to change notification settings - Fork 205
Feat: implement PWA support for offline access #684
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,63 @@ | ||||||||||||||
| import { defineConfig } from 'vite' | ||||||||||||||
| import react from '@vitejs/plugin-react' | ||||||||||||||
| import { VitePWA } from 'vite-plugin-pwa' // Import the PWA plugin | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check if vite-plugin-pwa is declared in package.json
if [ -f package.json ]; then
cat package.json | jq -r '.dependencies["vite-plugin-pwa"] // .devDependencies["vite-plugin-pwa"] // "NOT_FOUND"'
else
echo "package.json not found"
fiRepository: GitMetricsLab/github_tracker Length of output: 82 Add
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| export default defineConfig({ | ||||||||||||||
| plugins: [react()], | ||||||||||||||
| plugins: [ | ||||||||||||||
| react(), | ||||||||||||||
| // Add and configure the PWA plugin | ||||||||||||||
| VitePWA({ | ||||||||||||||
| registerType: 'autoUpdate', | ||||||||||||||
| includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'mask-icon.svg'], | ||||||||||||||
| manifest: { | ||||||||||||||
| name: 'GitHub Tracker', | ||||||||||||||
| short_name: 'GitTracker', | ||||||||||||||
| description: 'Track your GitHub repository metrics and contributions seamlessly.', | ||||||||||||||
| theme_color: '#0d1117', | ||||||||||||||
| background_color: '#0d1117', | ||||||||||||||
| display: 'standalone', | ||||||||||||||
| orientation: 'portrait', | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using 'any' for orientation to support desktop and tablet users. Restricting orientation to 📱 Suggested fix to support all orientations display: 'standalone',
- orientation: 'portrait',
+ orientation: 'any',
start_url: '/',📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| start_url: '/', | ||||||||||||||
| icons: [ | ||||||||||||||
| { | ||||||||||||||
| src: 'crl.png', | ||||||||||||||
| sizes: '192x192', | ||||||||||||||
| type: 'image/png', | ||||||||||||||
| purpose: 'any' | ||||||||||||||
| }, | ||||||||||||||
| { | ||||||||||||||
| src: 'crl.png', | ||||||||||||||
| sizes: '512x512', | ||||||||||||||
| type: 'image/png', | ||||||||||||||
| purpose: 'any' | ||||||||||||||
| } | ||||||||||||||
| ] | ||||||||||||||
|
Comment on lines
+21
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check if crl.png exists and report its dimensions
fd -t f "^crl\.png$" public/ -x file {} \; -x identify -format "%f: %wx%h\n" {} 2>/dev/null || echo "crl.png not found or 'identify' (ImageMagick) not available"
# List all PNG files in public directory that might be icons
echo -e "\nAll PNG files in public directory:"
fd -e png . public/Repository: GitMetricsLab/github_tracker Length of output: 203 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== vite.config.ts (around icons config) =="
if [ -f "vite.config.ts" ]; then
sed -n '1,120p' vite.config.ts | nl -ba | sed -n '15,60p'
else
echo "vite.config.ts not found"
fi
echo
echo "== Search for crl.png usage =="
rg -n "crl\.png" . || true
echo
echo "== Public PNG files =="
fd -e png . public/ | sort || true
echo
echo "== Dimensions via Pillow (crl.png, crl-icon.png) =="
python3 - <<'PY'
from PIL import Image
import os, sys
paths = []
for p in ["public/crl.png", "public/crl-icon.png"]:
if os.path.exists(p):
paths.append(p)
if not paths:
print("No expected icon files found in public/.")
sys.exit(0)
for p in paths:
with Image.open(p) as img:
print(f"{p}: {img.size[0]}x{img.size[1]}")
PYRepository: GitMetricsLab/github_tracker Length of output: 176 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Locate vite.config.ts =="
fd -t f "vite.config.ts" . || true
echo
echo "== Show vite.config.ts around 'icons' if found =="
path="$(fd -t f "vite.config.ts" . | head -n 1 || true)"
if [ -n "${path}" ] && [ -f "${path}" ]; then
echo "-- file: ${path} --"
# Print a small window around the first occurrence of "icons"
awk '
{ if ($0 ~ /icons[[:space:]]*:/ && start==0) { start=NR-10; if (start<1) start=1; }
if (start>0 && NR>=start && NR<=start+80) print NR ":" $0
if (start>0 && NR>=start+80) { exit }
}
' "${path}"
else
echo "vite.config.ts not found in repo."
fi
echo
echo "== Search for crl.png usage =="
rg -n "crl\.png" . || true
echo
echo "== Public PNG files =="
fd -e png . public/ | sort || true
echo
echo "== Dimensions via Pillow =="
python3 - <<'PY'
from PIL import Image
import os
paths = ["public/crl.png", "public/crl-icon.png", "public/crl.png".replace("public/","")]
# Deduplicate existing paths
paths = [p for p in ["public/crl.png","public/crl-icon.png"] if os.path.exists(p)]
if not paths:
print("No expected icon files found in public/.")
raise SystemExit(0)
for p in paths:
with Image.open(p) as img:
print(f"{p}: {img.size[0]}x{img.size[1]}")
PYRepository: GitMetricsLab/github_tracker Length of output: 1777 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Search for crl-icon.png usage =="
rg -n "crl-icon\.png" . || true
echo
echo "== Install Pillow (needed for dimensions) =="
python3 -m pip -q install Pillow
echo
echo "== Dimensions via Pillow =="
python3 - <<'PY'
from PIL import Image
import os
paths = ["public/crl.png", "public/crl-icon.png"]
for p in paths:
if not os.path.exists(p):
print(f"{p}: MISSING")
continue
with Image.open(p) as img:
print(f"{p}: {img.size[0]}x{img.size[1]}")
PYRepository: GitMetricsLab/github_tracker Length of output: 692 🏁 Script executed: #!/bin/bash
set -euo pipefail
python3 -m pip -q install Pillow
python3 - <<'PY'
from PIL import Image
img = Image.open('public/crl.png')
print(f"public/crl.png dimensions: {img.size[0]}x{img.size[1]} (expected 192x192 and 512x512 per vite.config.ts)")
PYRepository: GitMetricsLab/github_tracker Length of output: 157 🏁 Script executed: python3 -m pip -q install Pillow
python3 - <<'PY'
from PIL import Image
img = Image.open('public/crl.png')
print('public/crl.png:', img.size)
PYRepository: GitMetricsLab/github_tracker Length of output: 99 Critical: PWA
🎨 Recommended fix: reference correctly sized square icons for each declared size icons: [
{
- src: 'crl.png',
+ src: 'icon-192.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any'
},
{
- src: 'crl.png',
+ src: 'icon-512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any'
}
]🤖 Prompt for AI Agents |
||||||||||||||
| }, | ||||||||||||||
| workbox: { | ||||||||||||||
| globPatterns: ['**/*.{js,css,html,ico,png,svg}'], | ||||||||||||||
| runtimeCaching: [ | ||||||||||||||
| { | ||||||||||||||
| urlPattern: /^https:\/\/api\.github\.com\/.*/i, | ||||||||||||||
| handler: 'NetworkFirst', | ||||||||||||||
| options: { | ||||||||||||||
| cacheName: 'github-api-cache', | ||||||||||||||
| expiration: { | ||||||||||||||
| maxEntries: 50, | ||||||||||||||
| maxAgeSeconds: 60 * 60 * 24 | ||||||||||||||
| }, | ||||||||||||||
| cacheableResponse: { | ||||||||||||||
| statuses: [0, 200] | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+48
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Major: Including status 0 in cacheableResponse may cache CORS errors. The 🔧 Recommended fix: Cache only successful responses cacheableResponse: {
- statuses: [0, 200]
+ statuses: [200]
}If the app needs to cache other successful GitHub API response codes, consider: - statuses: [0, 200]
+ statuses: [200, 201, 204]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| ] | ||||||||||||||
| } | ||||||||||||||
| }) | ||||||||||||||
| ], | ||||||||||||||
| // Your existing test configuration remains exactly the same | ||||||||||||||
| test: { | ||||||||||||||
| globals: true, | ||||||||||||||
| environment: 'jsdom', | ||||||||||||||
| setupFiles: './src/setupTests.ts', | ||||||||||||||
| }, | ||||||||||||||
| }) | ||||||||||||||
| }) | ||||||||||||||
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.
Add error handling around service worker registration.
Calling
registerSW({ immediate: true })synchronously before React rendering means any error (unsupported browser, misconfigured plugin, HTTP context) will prevent the entire app from initializing. Users would see a blank page instead of a helpful error or the app functioning without PWA features.🛡️ Recommended fix: Wrap registration in try-catch
// Import the service worker registration from the virtual module import { registerSW } from "virtual:pwa-register"; -// Register the service worker to handle automatic background updates -registerSW({ immediate: true }); + +// Register the service worker to handle automatic background updates +// Wrapped in try-catch to prevent blocking app initialization if SW fails +try { + registerSW({ immediate: true }); +} catch (error) { + console.warn('Service worker registration failed:', error); + // App will continue to function without PWA features +}This ensures the app remains functional even if PWA features are unavailable.
📝 Committable suggestion
🤖 Prompt for AI Agents