Legacy grids: published head stacks pre-hook card grids on phones (no re-save)

Stored pages (generated at editor-save time) from before release 2026.11.5 carry
FeaturesGrid / Testimonials / NumberCounter grids without data-wsb-grid, so a
republish kept repeat(N,1fr) on phones (OLS home: body 594px wide at 360).
The <=767px block now matches the exact inline styles those emitters stored
(whole-attribute signatures; no spaces, as in git history and every stored
OLS/TTM page). Gallery shares the prefix with a free gap and keeps its columns:
the two colliding signatures carry :not(:has(> * > Gallery thumbnail)) in their
own rule (a browser without :has drops only that rule). Customer grids never
match. Mirrored byte-for-byte by WHP generateCompiledHTML (fix/legacy-grid-backend).

Tests: vitest selector contract (legacy shapes match, == current emitters minus
the hook, Gallery and customer grids never match, pretty == minified); head
parity pins updated; new real-browser suite test:browser:legacy-grid (Chromium +
Firefox, 360/390/768/1280) on the stored OLS home page + synthetic legacy grids;
colors suite folds the new rules back like the mobile-guard ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-01 16:26:11 -08:00
1 parent 322742aa81
commit 96670b94f8
13 files changed
+460 -12

No files matched your search

+7 -1
View File
@@ -34,6 +34,11 @@ const BASE_COMMIT = process.env.COLOR_BASE_COMMIT || '69fd34b';
// Deliberate head changes made AFTER the base, folded back before the comparison so it still proves the
// colour feature changed nothing else. Each `from` must occur exactly once (checked).
const HEAD_FOLDS = [
{
why: 'legacy-grid: stored (pre-hook) card-grid signatures right after [data-wsb-grid] in the <=767px block',
from: '[data-wsb-grid]{grid-template-columns:minmax(0,1fr)!important}[style^="max-width:1100px;margin:0 auto;display:grid;grid-template-columns:repeat("][style$=",1fr);gap:32px;text-align:center"]{grid-template-columns:minmax(0,1fr)!important}[style="max-width:1100px;margin:0 auto;display:grid;grid-template-columns:repeat(3,1fr);gap:32px"]:not(:has(>*>img[style^="width:100%;height:200px;object-fit:cover"])),[style^="max-width:1100px;margin:0 auto;display:grid;grid-template-columns:repeat("][style$=",1fr);gap:24px"]:not(:has(>*>img[style^="width:100%;height:200px;object-fit:cover"])){grid-template-columns:minmax(0,1fr)!important}',
to: '[data-wsb-grid]{grid-template-columns:minmax(0,1fr)!important}',
},
{
why: 'mobile-guard: card-grid / long-word / HtmlBlock media rules in the <=767px block; Navbar wrap moved to <=991px',
from: '[class^="cols_"]{flex-direction:column!important;align-items:stretch!important}[data-wsb-grid]{grid-template-columns:minmax(0,1fr)!important}body{overflow-wrap:break-word}[data-wsb-html] :is(img,video,iframe,embed,object,svg,canvas){max-width:100%}[data-wsb-html] :is(img,video){height:auto}[data-wsb-html] pre{max-width:100%;overflow-x:auto}}@media(max-width:991px){nav[class^="nav_"],nav[class^="nav_"] .navbar-links{flex-wrap:wrap}}',
@@ -41,7 +46,8 @@ const HEAD_FOLDS = [
},
];
const foldHead = (html) => HEAD_FOLDS.reduce((h, f) => (h.split(f.from).length === 2 ? h.replace(f.from, () => f.to) : h), html);
const foldsApplied = (html) => HEAD_FOLDS.map((f) => html.split(f.from).length - 1);
// Counted in order on the progressively folded document (a later fold's `from` may need an earlier fold applied).
const foldsApplied = (html) => HEAD_FOLDS.map((f) => { const n = html.split(f.from).length - 1; if (n === 1) html = html.replace(f.from, () => f.to); return n; });
const SHOTS = process.env.COLOR_SHOTS || '';
if (SHOTS) fs.mkdirSync(SHOTS, { recursive: true });
+51
View File
@@ -0,0 +1,51 @@
// Bundled (browser IIFE) by scripts/e2e-legacy-grid.mjs. Builds published documents from LEGACY stored HTML
// (pages saved before the data-wsb-grid hook existed) wrapped in the REAL Preview/publish head
// (exportComposedPreviewHtml: header + page + footer, as WHP handlePublish composes them; the head is byte-identical
// to WHP generateCompiledHTML, pinned on both sides by the head-parity tests).
import { exportBodyHtml, exportComposedPreviewHtml, RESPONSIVE_CSS_MINIFIED } from '../src/utils/html-export';
import { componentResolver } from '../src/components/resolver';
import olsHeader from '../tests/fixtures/legacy-grid/ols.header.html';
import olsIndex from '../tests/fixtures/legacy-grid/ols.index.html';
import olsFooter from '../tests/fixtures/legacy-grid/ols.footer.html';
import olsDesign from '../tests/fixtures/legacy-grid/ols.design.json';
type N = Record<string, any>;
const EMPTY = JSON.stringify({ ROOT: { type: { resolvedName: 'Container' }, isCanvas: true, props: { tag: 'div', style: {} }, displayName: 'Container', custom: {}, hidden: false, nodes: [], linkedNodes: {} } });
const defaults = (type: string): Record<string, unknown> => {
const c = (componentResolver as any)[type];
return c?.craft?.props ? JSON.parse(JSON.stringify(c.craft.props)) : {};
};
const node = (type: string, props: Record<string, unknown>, extra: N = {}) => ({
type: { resolvedName: type }, isCanvas: type === 'Container', props: { ...defaults(type), ...props }, displayName: type,
custom: {}, hidden: false, nodes: [], linkedNodes: {}, ...extra,
});
const stripHook = (html: string) => html.replace(/ data-wsb-grid(="")?/g, '');
const doc = (body: string, title: string) => exportComposedPreviewHtml(EMPTY, body, { title, design: olsDesign as any });
/** Every card-grid emitter in its stored (pre-hook) form, Galleries whose gap collides with a card-grid
* signature, and an unwrapped customer grid (legacy HtmlBlock content has no data-wsb-html wrapper). */
function synthetic(): string {
const nodes: N = {};
const kids: string[] = [];
const add = (id: string, type: string, props: Record<string, unknown> = {}) => { nodes[id] = node(type, props, { parent: 'ROOT' }); kids.push(id); };
add('features', 'FeaturesGrid');
add('t2', 'Testimonials', { columns: 2 });
add('t3', 'Testimonials');
add('t4', 'Testimonials', { columns: 4 });
add('counter', 'NumberCounter', { columns: 4 });
add('gal', 'Gallery');
add('gal32', 'Gallery', { columns: 3, gap: '32px', lightbox: true });
add('gal24', 'Gallery', { columns: 4, gap: '24px' });
nodes.ROOT = node('Container', { tag: 'div', style: {} }, { nodes: kids });
const body = stripHook(exportBodyHtml(JSON.stringify(nodes)).html);
const customer = '<div id="customer" style="padding:16px"><div style="display:grid;grid-template-columns:repeat(3,1fr);gap:32px"><div>One</div><div>Two</div><div>Three</div></div></div>';
return olsHeader + '\n' + body + customer + '\n' + olsFooter;
}
(window as any).wsbLegacyGridDocs = (): Record<string, string> => ({
ols: doc(olsHeader + '\n' + olsIndex + '\n' + olsFooter, 'Home'),
// The same page as a re-save in 2026.11.5 would store it (hook added): phones must look identical.
olsResaved: doc(olsHeader + '\n' + olsIndex.replace('<div style="max-width:1100px;margin:0 auto;display:grid;', '<div data-wsb-grid style="max-width:1100px;margin:0 auto;display:grid;') + '\n' + olsFooter, 'Home'),
synthetic: doc(synthetic(), 'Legacy grids'),
});
(window as any).wsbResponsiveCss = RESPONSIVE_CSS_MINIFIED;
+179
View File
@@ -0,0 +1,179 @@
#!/usr/bin/env node
/**
* Legacy card grids: real-browser (Chromium AND Firefox, headless) proof that the published head stacks card grids
* stored BEFORE the data-wsb-grid hook existed (no re-save needed), and changes nothing else.
*
* npm run test:browser:legacy-grid
*
* Documents (scripts/e2e-legacy-grid-entry.ts, real exporter head):
* ols - the OLS Digital home page exactly as stored on the site (tests/fixtures/legacy-grid: header +
* page + footer, no data-wsb-* attributes; its FeaturesGrid is the legacy inline repeat(3,1fr))
* olsResaved - the same page with the hook added, i.e. what a re-save stores today
* synthetic - every card-grid emitter in its stored form (FeaturesGrid, Testimonials 2/3/4, NumberCounter 4),
* Galleries whose gap collides with a card-grid signature (3 cols gap 32px + lightbox, 4 cols gap
* 24px) plus a default one, and an unwrapped customer grid (legacy HtmlBlock content)
* measured at 360 / 390 / 768 / 1280.
*
* Asserted (every doc, every width unless noted):
* - no horizontal overflow: body.scrollWidth <= viewport and the right edge of every visible element box and text
* line <= viewport (html,body{overflow-x:clip} hides overflow from documentElement.scrollWidth), and the page
* cannot be scrolled sideways
* - <=767px: every legacy card grid is one card per row; every Gallery keeps more than one column; the customer
* grid keeps its 3 columns. Discriminating signal: with the legacy rules removed from the head, the same
* legacy card grids are back to several per row (so the rules, not something else, stack them)
* - <=767px: the legacy OLS page is pixel-identical to its re-saved (hooked) form
* - 768 and 1280: every element box AND the full-page screenshot are identical with vs without the legacy rules
*
* Env: CHROMIUM_PATH / FIREFOX_PATH (when the Playwright-pinned builds are not installed), LEGACY_ONLY=chromium|firefox.
*/
import { chromium, firefox } from '@playwright/test';
import { build as esbuild } from 'esbuild';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const out = await esbuild({
entryPoints: [path.join(root, 'scripts/e2e-legacy-grid-entry.ts')],
bundle: true, write: false, format: 'iife', platform: 'browser', jsx: 'automatic', logLevel: 'error',
loader: { '.html': 'text' },
define: { 'process.env.NODE_ENV': '"production"', __EDITOR_BUILD__: '"test"' },
});
const js = out.outputFiles[0].text;
const WIDTHS = [360, 390, 768, 1280];
const MOBILE_MAX = 767;
/** Runs in the page. */
function measure() {
const vw = window.innerWidth;
const skip = new Set(['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEMPLATE']);
const contained = (el) => {
for (let a = el.parentElement; a && a !== document.body && a !== document.documentElement; a = a.parentElement) {
if (getComputedStyle(a).overflowX !== 'visible' && a.getBoundingClientRect().right <= vw + 0.5) return true;
}
return false;
};
const label = (el) => `${el.tagName.toLowerCase()} "${(el.textContent || '').trim().slice(0, 24)}"`;
let maxRight = 0; let worst = '';
const bump = (right, el) => { if (right > maxRight) { maxRight = right; worst = label(el); } };
for (const el of document.body.querySelectorAll('*')) {
if (skip.has(el.tagName)) continue;
const r = el.getBoundingClientRect();
if (!(r.width || r.height) || getComputedStyle(el).visibility === 'hidden' || contained(el)) continue;
bump(r.right, el);
}
const tw = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
for (let n = tw.nextNode(); n; n = tw.nextNode()) {
const el = n.parentElement;
if (!el || skip.has(el.tagName) || !n.textContent.trim() || contained(n)) continue;
const range = document.createRange(); range.selectNodeContents(n);
for (const r of range.getClientRects()) if (r.width) bump(r.right, el);
}
const grids = [...document.querySelectorAll('div')].filter((d) => getComputedStyle(d).display === 'grid').map((g) => {
const kids = [...g.children].filter((k) => !skip.has(k.tagName) && k.getBoundingClientRect().height > 0);
const firstTop = kids.length ? Math.round(kids[0].getBoundingClientRect().top) : 0;
const kind = g.closest('#customer') ? 'customer'
: g.querySelector(':scope > * > img[style^="width:100%;height:200px;object-fit:cover"]') ? 'gallery' : 'card';
return { kind, hook: g.hasAttribute('data-wsb-grid'), n: kids.length, perRow: kids.filter((k) => Math.round(k.getBoundingClientRect().top) === firstTop).length };
});
return { vw, docSW: document.documentElement.scrollWidth, bodySW: document.body.scrollWidth, maxRight: Math.round(maxRight * 10) / 10, worst, grids };
}
function sidewaysScroll() {
const y = window.scrollY;
window.scrollTo(5000, y);
const x = window.scrollX;
window.scrollTo(0, y);
return x;
}
function boxes() {
return [...document.body.querySelectorAll('*')]
.filter((e) => !['SCRIPT', 'STYLE', 'NOSCRIPT'].includes(e.tagName))
.map((e) => { const r = e.getBoundingClientRect(); return [e.tagName, ...[r.x, r.y, r.width, r.height].map((v) => Math.round(v * 10) / 10)].join(','); });
}
let fail = 0;
const ok = (c, m) => { if (!c) { fail++; console.log(' FAIL', m); } };
const summary = [];
async function open(browser, html, w) {
const page = await browser.newPage({ viewport: { width: w, height: 900 } });
await page.route(/^https?:/, (r) => r.abort()); // deterministic: no fonts/CDN/images racing the layout
await page.setContent(html, { waitUntil: 'load' });
await page.evaluate(() => document.fonts.ready);
await page.waitForTimeout(50);
return page;
}
async function run(name, launcher, exe) {
const browser = await launcher.launch({ executablePath: exe || undefined, ...(name === 'chromium' ? { args: ['--no-sandbox'] } : {}) });
const gen = await browser.newPage();
await gen.setContent('<!doctype html><html><body></body></html>');
await gen.addScriptTag({ content: js });
const docs = await gen.evaluate(() => window.wsbLegacyGridDocs());
const css = await gen.evaluate(() => window.wsbResponsiveCss);
await gen.close();
// The legacy rules = everything between the [data-wsb-grid] rule and body{overflow-wrap...} in the head CSS.
const HOOK = '[data-wsb-grid]{grid-template-columns:minmax(0,1fr)!important}';
const legacy = css.slice(css.indexOf(HOOK) + HOOK.length, css.indexOf('body{overflow-wrap'));
ok(legacy.includes('[style^=') && legacy.includes(':has('), `[${name}] could not isolate the legacy rules from the head CSS: ${legacy}`);
const bodyOf = (h) => h.slice(h.indexOf('<body'));
ok(bodyOf(docs.olsResaved).includes('data-wsb-grid') && !bodyOf(docs.ols).includes('data-wsb'), `[${name}] fixture: ols must be hook-free and olsResaved hooked`);
const without = Object.fromEntries(Object.entries(docs).map(([k, v]) => {
ok(v.split(legacy).length === 2, `[${name}] ${k}: the head does not carry the legacy rules exactly once`);
return [k, v.replace(legacy, '')];
}));
for (const [docName, html] of Object.entries(docs)) {
for (const w of WIDTHS) {
const tag = `[${name} ${w}] ${docName}`;
const mobile = w <= MOBILE_MAX;
const page = await open(browser, html, w);
const m = await page.evaluate(measure);
const sx = await page.evaluate(sidewaysScroll);
ok(sx === 0, `${tag}: the page scrolls sideways (scrollX=${sx})`);
ok(m.bodySW <= w, `${tag}: body.scrollWidth ${m.bodySW} > ${w}`);
ok(m.maxRight <= w + 0.5, `${tag}: content reaches x=${m.maxRight}: ${m.worst}`);
const base = await open(browser, without[docName], w);
const mb = await base.evaluate(measure);
const fmt = (g) => g.map((x) => `${x.kind[0]}${x.perRow}/${x.n}`).join(',');
summary.push(`${name.padEnd(8)} ${String(w).padEnd(4)} ${docName.padEnd(10)} bodySW=${m.bodySW} maxRight=${m.maxRight} grids=${fmt(m.grids)} | without rules: bodySW=${mb.bodySW} maxRight=${mb.maxRight}${mb.maxRight > w + 0.5 ? ' (' + mb.worst + ')' : ''} grids=${fmt(mb.grids)}`);
const cards = m.grids.filter((g) => g.kind === 'card' && g.n > 1);
if (docName !== 'olsResaved') ok(cards.length > 0, `${tag}: no legacy card grid found (fixture broken)`);
if (mobile) {
for (const g of cards) ok(g.perRow === 1, `${tag}: a legacy card grid keeps ${g.perRow} per row on a phone`);
for (const g of m.grids.filter((x) => x.kind === 'gallery')) ok(g.perRow > 1, `${tag}: a Gallery lost its columns (${g.perRow} per row)`);
for (const g of m.grids.filter((x) => x.kind === 'customer')) ok(g.perRow === 3, `${tag}: the customer grid was reflowed (${g.perRow} per row)`);
if (docName !== 'olsResaved') {
const legacyCards = mb.grids.filter((g) => g.kind === 'card' && g.n > 1 && !g.hook);
ok(legacyCards.length > 0 && legacyCards.every((g) => g.perRow > 1), `${tag}: without the legacy rules the card grids were expected to keep their columns (${fmt(legacyCards)})`);
}
} else {
for (const g of cards) ok(g.perRow > 1, `${tag}: a card grid lost its columns at ${w} (${g.perRow} per row)`);
const [b1, b2] = [await page.evaluate(boxes), await base.evaluate(boxes)];
const diffs = b1.length !== b2.length ? Infinity : b1.filter((b, i) => b !== b2[i]).length;
ok(diffs === 0, `${tag}: ${diffs} element boxes differ with vs without the legacy rules`);
const [s1, s2] = [await page.screenshot({ fullPage: true }), await base.screenshot({ fullPage: true })];
ok(s1.equals(s2), `${tag}: full-page pixels differ with vs without the legacy rules`);
}
if (mobile && docName === 'ols') {
const resaved = await open(browser, docs.olsResaved, w);
const [s1, s2] = [await page.screenshot({ fullPage: true }), await resaved.screenshot({ fullPage: true })];
ok(s1.equals(s2), `${tag}: the legacy page differs from its re-saved (hooked) form on a phone`);
await resaved.close();
}
await base.close();
await page.close();
}
}
await browser.close();
}
const only = process.env.LEGACY_ONLY;
if (!only || only === 'chromium') await run('chromium', chromium, process.env.CHROMIUM_PATH);
if (!only || only === 'firefox') await run('firefox', firefox, process.env.FIREFOX_PATH);
console.log('\n' + summary.join('\n'));
console.log(fail ? `\n${fail} FAILED` : '\nall passed');
process.exit(fail ? 1 : 0);