Changeset 76f0e61 in Klonkt


Ignore:
Timestamp:
06/26/2026 03:32:31 PM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
b8bbe77
Parents:
a036251
Message:

fix(ios pwa): force masthead safe-area inline + detect standalone + bump SW

The PWA kept serving a stale shell so the env-based fix never reached it. Now: detect
standalone explicitly (larger Dynamic-Island fallback), set --ios-safe-top AND force the
masthead padding inline (survives a stale cached stylesheet), re-apply after htmx chrome
swaps. Bumped the service worker cache (v11 -> v12) so the PWA refreshes.

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/server.js

    ra036251 r76f0e61  
    395395  res.set('Cache-Control', 'no-cache');
    396396  res.send(`
    397 const CACHE_VERSION = 'pcms-v11-' + new Date().toISOString().split('T')[0];
     397const CACHE_VERSION = 'pcms-v12-' + new Date().toISOString().split('T')[0];
    398398self.addEventListener('install', e => {
    399399  e.waitUntil(caches.open(CACHE_VERSION).then(c => c.addAll(['/'])));
  • src/views/shell.ejs

    ra036251 r76f0e61  
    200200<link rel="stylesheet" href="/assets/css/style.css?v=54">
    201201<script>
    202 /* iOS safe-area, built by hand: env(safe-area-inset-top) resolves to 0 in some iOS
    203    states (Safari + standalone) even with viewport-fit=cover. Measure it directly, and
    204    if it comes back empty on a notch/Dynamic-Island iPhone, fall back to a fixed inset.
    205    The masthead reads --ios-safe-top. */
     202/* iOS safe-area, built by hand. env(safe-area-inset-top) resolves to 0 on this iOS in
     203   BOTH Safari and the installed PWA (standalone), even with viewport-fit=cover, so the
     204   masthead can't clear the camera. We measure env directly and, when it comes back empty
     205   on a notched iPhone, fall back to a fixed inset (a bit larger in standalone for the
     206   Dynamic Island). We set --ios-safe-top AND force the masthead padding inline — the
     207   latter survives a stale cached stylesheet that lacks the var. Re-applied after htmx
     208   chrome swaps (the top-nav is out-of-band swapped on navigation). */
    206209(function(){
    207210  var ua = navigator.userAgent || '';
    208211  var isIOS = /iP(hone|od|ad)/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
    209212  if (!isIOS) return;
    210   function setInset(){
     213  var standalone = (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) || navigator.standalone === true;
     214  function apply(){
    211215    if (!document.body) return;
    212216    var p = document.createElement('div');
     
    215219    var i = parseFloat(getComputedStyle(p).paddingTop) || 0;
    216220    p.remove();
    217     // env() gave nothing but this looks like a notched iPhone (logical height >= 812)
    218     // -> use a fixed status-bar inset so the masthead clears the camera anyway.
    219     if (i < 20 && Math.max(screen.width, screen.height) >= 812) i = 50;
     221    if (i < 20 && Math.max(screen.width, screen.height) >= 812) i = standalone ? 59 : 47;
    220222    document.documentElement.style.setProperty('--ios-safe-top', i + 'px');
    221   }
    222   if (document.body) setInset(); else document.addEventListener('DOMContentLoaded', setInset);
    223   window.addEventListener('orientationchange', function(){ setTimeout(setInset, 250); });
     223    var mh = document.querySelector('.masthead');
     224    if (mh) mh.style.paddingTop = 'calc(.55rem + ' + i + 'px)';
     225  }
     226  if (document.body) apply(); else document.addEventListener('DOMContentLoaded', apply);
     227  document.addEventListener('htmx:afterSettle', apply);
     228  window.addEventListener('orientationchange', function(){ setTimeout(apply, 250); });
    224229})();
    225230</script>
Note: See TracChangeset for help on using the changeset viewer.