Skip to content

Add the installable PWA shell, manifest, icons, and safe service worker #1721

Closed

Description

@propr-dev

Context

The mobile experience must be installable before it can receive iOS/iPadOS Home Screen Web Push and icon badges. The service worker should provide a focused install shell without caching authenticated API responses or stale task data.

WebKit documents Home Screen Web Push support beginning with iOS/iPadOS 16.4 and notes that Apple Developer Program membership is not required: https://webkit.org/blog/13878/web-push-for-web-apps-on-ios-and-ipados/

Requirements

  • Add a web app manifest with standalone display mode, theme colors, icons, and app shortcuts.
  • Add 192px, 512px, maskable, and Apple touch icons generated from the ProPR brand source.
  • Add iOS-capable manifest and theme metadata to index.html.
  • Add a service worker that caches only the static application shell.
  • Never cache /api, /socket.io, OAuth, runtime config.js, or non-GET requests.
  • Handle push display, notification clicks, deep links, local dismissal, and app badge updates.
  • Treat push payload data as untrusted and restrict opened URLs to same-origin app links or GitHub PR links.
  • Mutating actions such as stop or approve/execute must open the app; the service worker must not perform them directly.
  • Register the service worker only in production-capable browser environments.

Acceptance Criteria

  • Chromium reports the app as installable.
  • iOS/iPadOS Safari can add the app to the Home Screen with the expected icon.
  • Reloading after one successful visit can load the static shell during a temporary network failure.
  • API and authentication responses are never returned from the cache.
  • Push clicks focus an existing PWA window when possible and otherwise open the correct deep link.
  • A push payload cannot make the service worker open an arbitrary third-party URL.

Created by ProPR AI Planner

Activity

  1. propr-dev commented on Aug 2, 2026

    @propr-dev
    ContributorAuthor

    Suggested Implementation:

    Implementation Approach

    Use a hand-written service worker rather than a broad cache-first plugin preset. ProPR contains sensitive, rapidly changing operational data, so only versioned static assets and the navigation shell should be cached. Runtime API responses remain network-only. Notification action buttons are limited to View and Dismiss because destructive workflow actions require in-app confirmation and browser support for notification actions varies.

    File: propr-ui/public/manifest.webmanifest (new file)

    Why this file: The manifest supplies install metadata, standalone display behavior, icons, and shortcuts used by mobile launchers.

    {
      "id": "/",
      "name": "ProPR",
      "short_name": "ProPR",
      "description": "Review plans, monitor tasks, and act on pull requests from ProPR.",
      "start_url": "/inbox?source=pwa",
      "scope": "/",
      "display": "standalone",
      "background_color": "#ffffff",
      "theme_color": "#1d8a8a",
      "orientation": "any",
      "icons": [
        { "src": "/icons/propr-192.png", "sizes": "192x192", "type": "image/png" },
        { "src": "/icons/propr-512.png", "sizes": "512x512", "type": "image/png" },
        { "src": "/icons/propr-maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
      ],
      "shortcuts": [
        { "name": "Inbox", "url": "/inbox?source=shortcut", "icons": [{ "src": "/icons/propr-192.png", "sizes": "192x192" }] },
        { "name": "New Plan", "url": "/studio/new?source=shortcut", "icons": [{ "src": "/icons/propr-192.png", "sizes": "192x192" }] }
      ]
    }

    File: propr-ui/public/icons/propr-pwa-source.svg (new file)

    Why this file: Keep a reviewable vector source in the repository so committed PNG icons can be reproduced instead of becoming unexplained binary artifacts.

    <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'>
      <!-- The generous background safe area protects the mark from maskable-icon crops. -->
      <rect width='512' height='512' rx='112' fill='#1d8a8a'/>
      <path fill='#ffffff' d='M138 116h130c76 0 122 40 122 108 0 70-48 112-128 112h-48v60h-76V116zm76 64v92h45c36 0 55-16 55-47 0-30-19-45-55-45h-45z'/>
    </svg>

    Binary assets to add

    Why these files: iOS uses the Apple touch icon rather than relying solely on the manifest. Generate these from the SVG above using the repository's approved palette and commit the output so production builds need no image-generation dependency.

    propr-ui/public/icons/propr-192.png             192x192 PNG
    propr-ui/public/icons/propr-512.png             512x512 PNG
    propr-ui/public/icons/propr-maskable-512.png    512x512 PNG with the mark inside the 80% safe zone
    propr-ui/public/icons/apple-touch-icon.png      180x180 opaque PNG
    

    File: propr-ui/index.html

    Why this file: Safari reads several installation hints directly from HTML, and the manifest must be discoverable before React boots.

    --- a/propr-ui/index.html
    +++ b/propr-ui/index.html
    @@ -3,6 +3,12 @@
       <head>
    +    <!-- Keep install metadata in static HTML so mobile browsers can discover it
    +         even when authentication or the API is temporarily unavailable. -->
    +    <link rel='manifest' href='/manifest.webmanifest'>
    +    <link rel='apple-touch-icon' href='/icons/apple-touch-icon.png'>
    +    <meta name='theme-color' content='#1d8a8a'>
    +    <meta name='apple-mobile-web-app-capable' content='yes'>
    +    <meta name='apple-mobile-web-app-status-bar-style' content='default'>
    +    <meta name='apple-mobile-web-app-title' content='ProPR'>

    File: propr-ui/public/sw.js (new file)

    Why this file: The service worker owns shell caching, push display, notification click routing, and background badge changes.

    const CACHE_NAME = 'propr-shell-v1';
    const SHELL_ASSETS = ['/', '/manifest.webmanifest', '/icons/propr-192.png', '/icons/propr-512.png'];
    
    self.addEventListener('install', event => {
      // Cache only public shell files; authenticated API content must never be
      // persisted in a shared browser cache by this worker.
      event.waitUntil(caches.open(CACHE_NAME).then(cache => cache.addAll(SHELL_ASSETS)));
    });
    
    self.addEventListener('activate', event => {
      event.waitUntil(Promise.all([
        caches.keys().then(keys => Promise.all(keys.filter(key => key !== CACHE_NAME).map(key => caches.delete(key)))),
        self.clients.claim(),
      ]));
    });
    
    const isSensitivePath = url =>
      url.pathname.startsWith('/api/') ||
      url.pathname.startsWith('/socket.io/') ||
      url.pathname.startsWith('/login') ||
      url.pathname.includes('/auth/') ||
      url.pathname === '/config.js';
    
    self.addEventListener('fetch', event => {
      const request = event.request;
      const url = new URL(request.url);
      if (request.method !== 'GET' || url.origin !== self.location.origin || isSensitivePath(url)) return;
    
      if (request.mode === 'navigate') {
        event.respondWith(fetch(request).catch(() => caches.match('/')));
        return;
      }
    
      event.respondWith(caches.match(request).then(cached => cached || fetch(request).then(response => {
        // Cache immutable-looking successful static resources only. Avoid caching
        // opaque responses or dynamic HTML returned under asset-looking URLs.
        if (response.ok && ['script', 'style', 'image', 'font'].includes(request.destination)) {
          const copy = response.clone();
          void caches.open(CACHE_NAME).then(cache => cache.put(request, copy));
        }
        return response;
      })));
    });
    
    const safeAppPath = value => {
      try {
        const url = new URL(value || '/inbox', self.location.origin);
        return url.origin === self.location.origin ? `${url.pathname}${url.search}${url.hash}` : '/inbox';
      } catch {
        return '/inbox';
      }
    };
    
    const safePrUrl = value => {
      try {
        const url = new URL(value);
        return url.protocol === 'https:' && url.hostname === 'github.com' ? url.href : null;
      } catch {
        return null;
      }
    };
    
    const setBadge = async count => {
      if (!self.navigator?.setAppBadge) return;
      if (Number(count) > 0) await self.navigator.setAppBadge(Number(count));
      else if (self.navigator.clearAppBadge) await self.navigator.clearAppBadge();
    };
    
    self.addEventListener('push', event => {
      let data = {};
      try { data = event.data?.json() ?? {}; } catch { data = {}; }
      const deepLink = safeAppPath(data.deepLink);
      event.waitUntil(Promise.all([
        self.registration.showNotification(String(data.title || 'ProPR update'), {
          body: String(data.body || 'Open ProPR for details.'),
          icon: '/icons/propr-192.png',
          badge: '/icons/propr-192.png',
          tag: data.id ? `propr-${data.id}` : undefined,
          renotify: false,
          data: {
            id: String(data.id || ''),
            deepLink,
            prUrl: safePrUrl(data.prUrl),
            apiBaseUrl: typeof data.apiBaseUrl === 'string' ? data.apiBaseUrl : '',
          },
          actions: [
            { action: 'view', title: 'View' },
            { action: 'dismiss', title: 'Dismiss' },
          ],
        }),
        setBadge(data.unreadCount),
      ]));
    });
    
    async function focusOrOpen(path) {
      const windows = await self.clients.matchAll({ type: 'window', includeUncontrolled: true });
      const existing = windows.find(client => new URL(client.url).origin === self.location.origin);
      if (existing) {
        await existing.navigate(path);
        return existing.focus();
      }
      return self.clients.openWindow(path);
    }
    
    self.addEventListener('notificationclick', event => {
      event.notification.close();
      const data = event.notification.data || {};
      if (event.action === 'dismiss') {
        // Local dismissal is immediate. The app reconciles server receipt state on
        // its next foreground load if a cross-origin tunnel request is unavailable.
        event.waitUntil(focusOrOpen(`/inbox?intent=dismiss&notification=${encodeURIComponent(data.id || '')}`));
        return;
      }
      const target = event.action === 'open_pr' && data.prUrl ? data.prUrl : safeAppPath(data.deepLink);
      event.waitUntil(focusOrOpen(target));
    });
    
    self.addEventListener('message', event => {
      if (event.data?.type === 'SKIP_WAITING') self.skipWaiting();
      if (event.data?.type === 'SET_BADGE') event.waitUntil(setBadge(event.data.count));
    });

    File: propr-ui/src/pwa/registerServiceWorker.ts (new file)

    Why this file: Registration is isolated from React rendering and fails quietly on unsupported browsers or local test environments.

    export async function registerServiceWorker(): Promise<ServiceWorkerRegistration | null> {
      if (!('serviceWorker' in navigator) || import.meta.env.MODE === 'test') return null;
      try {
        // Register after the page is usable so service-worker startup does not delay
        // authentication or the first dashboard render.
        return await navigator.serviceWorker.register('/sw.js', { scope: '/' });
      } catch (error) {
        console.warn('[propr] Service worker registration failed', error);
        return null;
      }
    }

    File: propr-ui/src/main.tsx

    Why this file: The application entry point registers the worker once after page load.

    --- a/propr-ui/src/main.tsx
    +++ b/propr-ui/src/main.tsx
    @@ -1,5 +1,6 @@
    +import { registerServiceWorker } from './pwa/registerServiceWorker';
    @@ -20,3 +21,8 @@
    +window.addEventListener('load', () => {
    +  // Registration is intentionally non-blocking; PWA support must not prevent
    +  // the normal web dashboard from starting.
    +  void registerServiceWorker();
    +});
  2. propr-dev commented on Aug 24, 2026

    @propr-dev
    ContributorAuthor

    🤖 AI processing has started for this issue using codex agent with gpt-5.6-sol model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: codex
    • Model: gpt-5.6-sol
    • Branch: 1721/gpt-5.6-sol-add-the-installable-pwa-s-20260824-1058-f1o
    • Base Branch: 1716-epic-failed-to-3m8
    • Worktree: issue-1721-20260824-1058-gpt-5.6-sol-f1o

    🔍 Track Task Execution

  3. added a commit that references this issue on Aug 24, 2026
  4. added a commit that references this issue on Aug 24, 2026
  5. added a commit that references this issue on Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions