Act on the fragility audit: boot-order crash, real cache correctness, deep links
A 55-agent audit of the last few commits confirmed 32 findings. The high and medium ones are fixed here; the ranked leftovers are listed at the end. Boot-order crash (my regression, wave 2) - wp-format.js loaded AFTER wp-creation-app.js on every page, but the creator boots synchronously at parse time and its comment renderer calls wpFormatDateTime(). With any review comment present that threw a ReferenceError and aborted the rest of boot. The formatter now parses before the app scripts on all five pages. Verified with a comment seeded: the date renders and boot completes. The network-first fix didn't actually work - `fetch(req)` inherits the request's default cache mode, so it consults the browser HTTP cache — the previous commit's "network-first" still allowed a page to run against a stale sibling. Code is now fetched with cache:'no-cache' and precached with cache:'reload'. - Nothing pinned freshness on the wire either: no Cache-Control anywhere, so browsers applied heuristic caching (~10% of a file's age) and each file expired at a different moment. NGINX and the dev server now send no-cache for html/css/js/ webmanifest; images stay cacheable. Verified on the wire. - Non-ok responses were returned verbatim, so a 502 broke pages the cache could have served; they now fall back to the cache. Cache keys drop the query string, which fixes both the offline miss on every in-app link (?project=…&tab=…) and unbounded cache growth. respondWith can no longer resolve to undefined. Cache bumped to v5. Embedded creator - Dropped the &t=Date.now() cache-buster and made the frame's identity the PROJECT. The view and which package to open are now applied by calling into the loaded document, so switching tabs no longer reloads it — that reload discarded unsaved form edits, made the creator unreachable offline, and stored a fresh copy per click. - ?view=dashboard was re-read on every tab switch, so after one deep link the "Work Package Creation" tab kept opening the Dashboard for the rest of the session. Deep-link params are consumed once now. - ?wp=<id> — which the global search has been emitting since wave 2 — was read by nothing, so picking a work package in search opened a blank one. The creator now exposes openWpById() and the shell applies it after a new 'wp-creator-ready' event, because the frame's load fires before pullProject() resolves. - Math.max(320,…) could make the frame taller than the space available while page scrolling was disabled, pushing content off a window that couldn't scroll. Full-bleed is now only used when at least 460px remains, and the SOP-incomplete gate never runs inside it. A ResizeObserver re-measures when wp-chrome.js grows the app bar. Contract drift - .field-hint and .user-pick are used on the SOP suite page but their only rules lived in wp-creation-styles.css, which that page doesn't link — the CM hint and the sign-off pickers had no styling at all. Rules added to the suite's stylesheet. - The creator's critical floor now also hides modal overlays (a stale stylesheet rendered their contents inline in the form) and gives the jump bar a sane sticky top. - login.js dereferenced ids unguarded where the old version guarded, so a cached older login.html would break sign-in itself. Guarded. - The "Language & time" menu item was added only if wp-format.js had already parsed; the check now happens at click time. Verified: 157 API checks across five suites on a clean database, plus 22 driven UI checks — boot-with-comment, tab switching with a no-reload probe, short-viewport fallback, and the search deep link landing on the right package. Not done, ranked: ~50 dead CSS rules across three stylesheets; dead .team-pick and .constraint-option contracts; wp-chrome.js's documented '.header' mount branch is unreachable because the creator loads neither wp-chrome.js nor its CSS; the squeeze half of the embed layout (.content-area.embed-full) is still CSS-only, which degrades to the old narrow column rather than breaking; fingerprinted asset URLs would make a mismatched pair unrepresentable rather than merely unlikely. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -291,10 +291,15 @@ window.addEventListener('DOMContentLoaded',()=>{
|
||||
updateProjectDisplay();
|
||||
loadProjectUsers(); // team pickers: who's on this project
|
||||
applyBimFlag(); // hide the BIM section unless an admin enabled it
|
||||
// Deep-link: ?tab=sop | ?tab=wp | ?view=dashboard from the home page.
|
||||
// Deep-link: ?tab=sop | ?tab=wp | ?view=dashboard | ?wp=<id>. Consumed ONCE —
|
||||
// leaving ?view=dashboard in the URL used to make the Work Package Creation tab
|
||||
// keep opening the dashboard for the rest of the session.
|
||||
const tab = params.get('tab');
|
||||
if(params.get('view') === 'dashboard') switchTool('dashboard');
|
||||
_deepLinkWp = params.get('wp') || '';
|
||||
const wantDashboard = params.get('view') === 'dashboard';
|
||||
if(wantDashboard) switchTool('dashboard');
|
||||
else if(tab === 'wp' || tab === 'sop') switchTool(tab);
|
||||
else if(_deepLinkWp) switchTool('wp');
|
||||
}
|
||||
if(projId && typeof ProjectData!=='undefined' && ProjectData.pullProject){
|
||||
ProjectData.pullProject(projId).then(afterPull).catch(afterPull);
|
||||
@@ -479,7 +484,10 @@ function switchTool(tool){
|
||||
document.getElementById('total-steps').textContent = (tool === 'sop') ? '10' : '—';
|
||||
|
||||
if(contentTool === 'wp') renderWPTab(isDash);
|
||||
applyEmbedLayout(contentTool === 'wp');
|
||||
// Only go full-bleed when the creator is actually showing. With the SOP
|
||||
// incomplete this tab shows a short 'complete the SOP first' gate; making the
|
||||
// page unscrollable around it can clip its button off the bottom.
|
||||
applyEmbedLayout(contentTool === 'wp' && sopComplete);
|
||||
|
||||
updateStepUI();
|
||||
updateProjectDisplay();
|
||||
@@ -488,13 +496,23 @@ function switchTool(tool){
|
||||
// The embedded creator/dashboard fills the window below the app chrome, so there
|
||||
// is ONE scrollbar (the iframe's) instead of a skinny inner pane inside a scrolling
|
||||
// page — and the creator's sticky bars have a real viewport to stick to.
|
||||
// A work package the global search asked us to open, handed to the creator on its
|
||||
// next load and then cleared.
|
||||
let _deepLinkWp = '';
|
||||
|
||||
function applyEmbedLayout(on){
|
||||
// Below this, "fill the window" leaves nothing usable: the iframe would be shorter
|
||||
// than the creator's own sticky bars while the page itself can't scroll. Fall back
|
||||
// to normal page flow and let the page scroll instead.
|
||||
const MIN_FILL_H = 460;
|
||||
const fits = (window.innerHeight - chromeHeight()) >= MIN_FILL_H;
|
||||
const full = !!on && fits;
|
||||
const area = document.querySelector('.content-area');
|
||||
const frame = document.getElementById('wp-frame');
|
||||
if(area) area.classList.toggle('embed-full', !!on);
|
||||
if(frame) frame.classList.toggle('fill', !!on);
|
||||
document.body.classList.toggle('embed-full', !!on);
|
||||
sizeWPFrame(on);
|
||||
if(area) area.classList.toggle('embed-full', full);
|
||||
if(frame) frame.classList.toggle('fill', full);
|
||||
document.body.classList.toggle('embed-full', full);
|
||||
sizeWPFrame(full);
|
||||
}
|
||||
|
||||
// Size the frame with INLINE styles, not only CSS classes. Inline wins over any
|
||||
@@ -516,16 +534,30 @@ function sizeWPFrame(on){
|
||||
}
|
||||
}
|
||||
|
||||
// Whatever is left of the window below the app bar + tab strip.
|
||||
function viewportMinusChrome(){
|
||||
function chromeHeight(){
|
||||
const hdr = document.querySelector('.header');
|
||||
const nav = document.querySelector('.main-nav');
|
||||
const chrome = (hdr ? hdr.offsetHeight : 48) + (nav ? nav.offsetHeight : 48);
|
||||
return Math.max(320, window.innerHeight - chrome);
|
||||
return (hdr ? hdr.offsetHeight : 48) + (nav ? nav.offsetHeight : 48);
|
||||
}
|
||||
// Whatever is left of the window below the app bar + tab strip. No floor: a floor
|
||||
// taller than the remaining space pushes the frame (and the creator's fixed save bar)
|
||||
// off a window that has scrolling disabled.
|
||||
function viewportMinusChrome(){
|
||||
return Math.max(0, window.innerHeight - chromeHeight());
|
||||
}
|
||||
// Re-measure on resize, and re-decide whether full-bleed still fits.
|
||||
window.addEventListener('resize', () => {
|
||||
if(document.body.classList.contains('embed-full')) sizeWPFrame(true);
|
||||
if(currentTool === 'wp' || currentTool === 'dashboard') applyEmbedLayout(true);
|
||||
}, {passive:true});
|
||||
// The app bar grows when wp-chrome.js injects the project switcher and search, which
|
||||
// happens after the frame has already been sized. Watch the chrome instead of relying
|
||||
// on someone resizing the window.
|
||||
try {
|
||||
const _ro = new ResizeObserver(() => {
|
||||
if(document.body.classList.contains('embed-full')) sizeWPFrame(true);
|
||||
});
|
||||
['.header', '.main-nav'].forEach(sel => { const el = document.querySelector(sel); if(el) _ro.observe(el); });
|
||||
} catch(e) { /* no ResizeObserver: the resize handler above still covers it */ }
|
||||
|
||||
// Show the gate or the embedded Work Package Creator depending on SOP status.
|
||||
// wantDash=true opens the creator straight to the dashboard view.
|
||||
@@ -536,12 +568,49 @@ function renderWPTab(wantDash){
|
||||
if(sopComplete){
|
||||
gate.style.display = 'none';
|
||||
frame.style.display = 'block';
|
||||
// Reload each time so the creator picks up the latest SOP from localStorage.
|
||||
const sp = new URLSearchParams(window.location.search);
|
||||
const dash = wantDash || sp.get('view') === 'dashboard';
|
||||
const projId = sp.get('project') || (activeProject && activeProject.id) || '';
|
||||
frame.src = 'wp-creation-index.html?embedded=1' + (dash ? '&view=dashboard' : '')
|
||||
+ (projId ? '&project=' + encodeURIComponent(projId) : '') + '&t=' + Date.now();
|
||||
const wantWp = _deepLinkWp; _deepLinkWp = '';
|
||||
const dash = wantDash;
|
||||
|
||||
// The frame's identity is the PROJECT only. The view (form vs dashboard) and
|
||||
// which package to open are applied by calling into the loaded document, so
|
||||
// switching tabs never reloads it — reloading discarded unsaved form edits, made
|
||||
// the creator unreachable offline, and stored a fresh copy in the SW cache each
|
||||
// time. It's same-origin, so a direct call is fine.
|
||||
const src = 'wp-creation-index.html?embedded=1'
|
||||
+ (projId ? '&project=' + encodeURIComponent(projId) : '');
|
||||
|
||||
const applyNow = () => {
|
||||
try {
|
||||
const cw = frame.contentWindow;
|
||||
if(!cw) return;
|
||||
if(wantWp && typeof cw.openWpById === 'function' && !cw.openWpById(wantWp)){
|
||||
if(typeof cw.toast === 'function') cw.toast('That work package is not on this project.');
|
||||
}
|
||||
if(dash && typeof cw.showDashboard === 'function') cw.showDashboard();
|
||||
else if(!dash && typeof cw.showForm === 'function') cw.showForm();
|
||||
} catch(e){ /* cross-document timing; nothing useful to do */ }
|
||||
};
|
||||
// Wait for the creator's data, not just its document. `load` fires before
|
||||
// pullProject() resolves, so opening a specific package straight after load
|
||||
// silently found nothing.
|
||||
const whenReady = () => {
|
||||
try {
|
||||
const cw = frame.contentWindow;
|
||||
if(cw && cw.wpCreatorReady) { applyNow(); return; }
|
||||
if(cw && cw.document) { cw.document.addEventListener('wp-creator-ready', applyNow, {once:true}); return; }
|
||||
} catch(e){}
|
||||
applyNow();
|
||||
};
|
||||
|
||||
if(frame.getAttribute('data-src') === src && frame.contentWindow){
|
||||
whenReady();
|
||||
} else {
|
||||
frame.setAttribute('data-src', src);
|
||||
frame.addEventListener('load', whenReady, {once:true});
|
||||
frame.src = src;
|
||||
}
|
||||
}else{
|
||||
gate.style.display = 'block';
|
||||
frame.style.display = 'none';
|
||||
|
||||
Reference in New Issue
Block a user