The Creator rendered as a tiny double-scrolling square in the WP tab. My fault, and the mechanism matters more than the symptom: I had moved the iframe's sizing (width:100%, border:0, min-height) out of its inline style attribute and into work-package-suite-styles.css. The service worker cached the HTML and the stylesheet as INDEPENDENT entries, cache-first — so a browser could hold the new HTML together with the old CSS. With the inline sizing gone and the new rule absent, the iframe fell back to the HTML default 300x150 box and the whole tool collapsed. Moving self-contained markup into a separately-cached file created that window; nothing about the layout itself was wrong. Three layers so it cannot recur: - The iframe's width/border/min-height are inline again, on purpose, with a comment saying why. An iframe with no intrinsic size has a catastrophic failure mode, so its sizing must not depend on another file being in step. - applyEmbedLayout() now sets the fill height and width as INLINE styles via sizeWPFrame(). Inline beats any stylesheet, including a stale cached one, so the class is a refinement rather than a requirement. - sw.js: HTML/CSS/JS are now fetched NETWORK-FIRST with the cache as offline fallback; images/icons/manifest stay stale-while-revalidate. These files reference each other, so a page must never run against a stale sibling — this same staleness had already masked two other fixes during development. Cache bumped to v4. Verified: at 2560x1440 the tool spans the window with a single scrollbar; with work-package-suite-styles.css removed entirely (strictly worse than stale) the frame still measures 1469x662 instead of 300x150, and re-running the layout pass keeps it there; 12 checks across sop -> wp -> dashboard -> sop confirm body.embed-full, the content-area class, the fill class and the inline height are all cleared on the way out, so the wizard never ends up unscrollable. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
97 lines
3.8 KiB
JavaScript
97 lines
3.8 KiB
JavaScript
/* Service worker for the Work Package Suite PWA.
|
|
|
|
Goal: let the app (and especially the field view) load and run offline. Data
|
|
durability is already handled by the sync outbox in project-data.js — this
|
|
worker only caches the static app shell so the pages open without a network.
|
|
|
|
Strategy:
|
|
• /api/* and non-GET → never touched (pass straight to the network; offline
|
|
reads fall back to the app's localStorage cache, writes queue in the outbox).
|
|
• HTML / CSS / JS → network-first, cache as fallback. These reference each
|
|
other, so a page must never run against a stale sibling.
|
|
• images / icons / manifest → stale-while-revalidate (instant from cache).
|
|
*/
|
|
'use strict';
|
|
// Bumped when the shell file list changes, so clients fetch the new assets
|
|
// instead of serving a half-old shell from the previous cache.
|
|
const CACHE = 'wp-suite-shell-v4';
|
|
const SHELL = [
|
|
'/', '/index.html', '/work-package-suite.html', '/wp-creation-index.html',
|
|
'/field.html', '/login.html', '/admin.html',
|
|
'/theme-light.css', '/work-package-suite-styles.css', '/wp-creation-styles.css',
|
|
'/wp-chrome.css',
|
|
'/auth-guard.js', '/project-data.js', '/feedback-config.js', '/help.js',
|
|
'/work-package-suite-app.js', '/wp-creation-app.js', '/field.js',
|
|
'/wp-chrome.js', '/wp-format.js', '/login.js', '/admin.js',
|
|
'/prime-controls-logo.jpg', '/favicon.ico',
|
|
'/manifest.webmanifest', '/icon-192.png', '/icon-512.png',
|
|
];
|
|
|
|
self.addEventListener('install', (e) => {
|
|
// Cache each shell asset individually so one missing file doesn't abort install.
|
|
e.waitUntil(
|
|
caches.open(CACHE)
|
|
.then((c) => Promise.all(SHELL.map((u) => c.add(u).catch(() => {}))))
|
|
.then(() => self.skipWaiting())
|
|
);
|
|
});
|
|
|
|
self.addEventListener('activate', (e) => {
|
|
e.waitUntil(
|
|
caches.keys()
|
|
.then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
|
|
.then(() => self.clients.claim())
|
|
);
|
|
});
|
|
|
|
// Code (HTML / CSS / JS) is fetched NETWORK-FIRST, falling back to the cache when
|
|
// offline. Everything else (images, icons, the manifest) stays cache-first, which is
|
|
// where offline speed actually comes from.
|
|
//
|
|
// Why not cache-first for code: these files reference each other, and the cache
|
|
// stores them as independent entries. Cache-first served whichever copy of each file
|
|
// happened to be stored, so a browser could run new HTML against old CSS — which is
|
|
// exactly how the embedded creator once collapsed to a 300x150 iframe. A page must
|
|
// only ever run against the stylesheet and scripts it shipped with.
|
|
const CODE_RE = /\.(html|css|js)$|\/$/i;
|
|
|
|
self.addEventListener('fetch', (e) => {
|
|
const req = e.request;
|
|
if (req.method !== 'GET') return; // outbox owns writes
|
|
const url = new URL(req.url);
|
|
if (url.origin !== self.location.origin) return; // third-party: default
|
|
if (url.pathname.startsWith('/api/')) return; // never cache the API
|
|
|
|
const isCode = CODE_RE.test(url.pathname);
|
|
|
|
if (isCode) {
|
|
e.respondWith(
|
|
fetch(req)
|
|
.then((res) => {
|
|
if (res && res.ok) {
|
|
const copy = res.clone();
|
|
caches.open(CACHE).then((c) => c.put(req, copy));
|
|
}
|
|
return res;
|
|
})
|
|
.catch(() => caches.match(req)) // offline → last good copy
|
|
);
|
|
return;
|
|
}
|
|
|
|
e.respondWith(
|
|
caches.match(req).then((cached) => {
|
|
const network = fetch(req)
|
|
.then((res) => {
|
|
if (res && res.ok) {
|
|
const copy = res.clone();
|
|
caches.open(CACHE).then((c) => c.put(req, copy));
|
|
}
|
|
return res;
|
|
})
|
|
.catch(() => cached); // offline → cached copy
|
|
return cached || network; // cache-first, then refresh
|
|
})
|
|
);
|
|
});
|