fix: harden CHRNX stage reflow

This commit is contained in:
chrnx committed 2026-08-13 09:54:36 -05:00
1 parent d9d187a631
commit f276e6b2ea
4 files changed
+218 -66

No files matched your search

+2
View File
@@ -1360,6 +1360,8 @@ html[data-theme="light"] .chrnx-music-landing .chrnx-character-stage {
.chrnx-music-landing .chrnx-character-stage__content, .chrnx-music-landing .chrnx-character-stage__content,
.chrnx-podcast-landing .chrnx-character-stage__content { .chrnx-podcast-landing .chrnx-character-stage__content {
min-width: 0; min-width: 0;
overflow-wrap: anywhere;
word-break: normal;
} }
.chrnx-music-landing .chrnx-character-stage__content > h2, .chrnx-music-landing .chrnx-character-stage__content > h2,
+3 -2
View File
@@ -11,7 +11,8 @@
.chrnx-podcast-card__content { .chrnx-podcast-card__content {
min-width: 0; min-width: 0;
overflow-wrap: normal; overflow-wrap: anywhere;
word-break: normal;
} }
.chrnx-podcast-card__image, .chrnx-podcast-card__image,
@@ -29,7 +30,7 @@
.chrnx-podcast-card__title, .chrnx-podcast-card__title,
.chrnx-podcast-card__excerpt, .chrnx-podcast-card__excerpt,
.chrnx-podcast-card__badge { .chrnx-podcast-card__badge {
overflow-wrap: normal; overflow-wrap: anywhere;
word-break: normal; word-break: normal;
} }
+211 -62
View File
@@ -24,8 +24,27 @@ const landings = [
}, },
]; ];
async function setTheme( page, theme ) { async function openIsolatedThemedPage( browser, testInfo, { height, path, theme, width } ) {
await page.addInitScript( ( value ) => localStorage.setItem( 'chrnx-theme', value ), theme ); const baseURL = testInfo.project.use.baseURL;
expect( new URL( baseURL ).origin ).toBe( 'http://localhost:8908' );
const context = await browser.newContext( {
baseURL,
colorScheme: theme,
viewport: { width, height },
} );
const page = await context.newPage();
await page.goto( path );
const resolvedTheme = await page.evaluate( ( value ) => {
window.localStorage.clear();
window.localStorage.setItem( 'chrnx-theme', value );
document.documentElement.dataset.theme = value;
return {
attribute: document.documentElement.dataset.theme,
stored: window.localStorage.getItem( 'chrnx-theme' ),
};
}, theme );
expect( resolvedTheme ).toEqual( { attribute: theme, stored: theme } );
return { context, page };
} }
async function expectNoHorizontalOverflow( page ) { async function expectNoHorizontalOverflow( page ) {
@@ -99,16 +118,22 @@ async function readStage( page, landing ) {
} }
test( 'Music and Podcast page and stage titles center while internal headings stay aligned', async ( { test( 'Music and Podcast page and stage titles center while internal headings stay aligned', async ( {
page, browser,
} ) => { }, testInfo ) => {
test.setTimeout( 90_000 ); test.setTimeout( 180_000 );
for ( const theme of [ 'dark', 'light' ] ) { for ( const theme of [ 'dark', 'light' ] ) {
await setTheme( page, theme );
for ( const width of [ 375, 1440 ] ) { for ( const width of [ 375, 1440 ] ) {
await page.setViewportSize( { width, height: width === 375 ? 812 : 1024 } );
for ( const landing of landings ) { for ( const landing of landings ) {
await page.goto( landing.path ); const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
const state = await page.locator( 'main.chrnx-entry--page' ).evaluate( ( main, value ) => { height: width === 375 ? 812 : 1024,
path: landing.path,
theme,
width,
} );
try {
const state = await page
.locator( 'main.chrnx-entry--page' )
.evaluate( ( main, value ) => {
const root = main.querySelector( value.root ); const root = main.querySelector( value.root );
const pageTitle = main.querySelector( ':scope > h1.wp-block-post-title' ); const pageTitle = main.querySelector( ':scope > h1.wp-block-post-title' );
const stageTitle = root.querySelector( '.chrnx-character-stage__content > h2' ); const stageTitle = root.querySelector( '.chrnx-character-stage__content > h2' );
@@ -121,7 +146,8 @@ test( 'Music and Podcast page and stage titles center while internal headings st
return { return {
alignment: style.textAlign, alignment: style.textAlign,
centerDelta: Math.abs( centerDelta: Math.abs(
( textRect.left + textRect.right ) / 2 - ( titleRect.left + titleRect.right ) / 2, ( textRect.left + textRect.right ) / 2 -
( titleRect.left + titleRect.right ) / 2,
), ),
text: title.textContent.trim(), text: title.textContent.trim(),
}; };
@@ -153,25 +179,33 @@ test( 'Music and Podcast page and stage titles center while internal headings st
expect( expect(
state.internalAlignments.every( ( alignment ) => alignment === 'start' ), state.internalAlignments.every( ( alignment ) => alignment === 'start' ),
).toBeTruthy(); ).toBeTruthy();
} finally {
await context.close();
}
} }
} }
} }
} ); } );
test( 'desktop grunge stages compose atmosphere, copy, art, and latest in both themes', async ( { test( 'desktop grunge stages compose atmosphere, copy, art, and latest in both themes', async ( {
page, browser,
} ) => { }, testInfo ) => {
test.setTimeout( 90_000 ); test.setTimeout( 90_000 );
await page.setViewportSize( { width: 1440, height: 900 } );
for ( const theme of [ 'dark', 'light' ] ) { for ( const theme of [ 'dark', 'light' ] ) {
await setTheme( page, theme );
for ( const landing of landings ) { for ( const landing of landings ) {
await page.goto( landing.path ); const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
height: 900,
path: landing.path,
theme,
width: 1440,
} );
try {
const state = await readStage( page, landing ); const state = await readStage( page, landing );
expect( state.stage.height, `${ landing.name } ${ theme } stage height` ).toBeLessThanOrEqual( expect(
Math.min( 900, REM_46 ) + 1, state.stage.height,
); `${ landing.name } ${ theme } stage height`,
).toBeLessThanOrEqual( Math.min( 900, REM_46 ) + 1 );
expect( state.atmosphereContained ).toBeTruthy(); expect( state.atmosphereContained ).toBeTruthy();
expect( state.atmosphereFit ).toBe( 'cover' ); expect( state.atmosphereFit ).toBe( 'cover' );
expect( state.artContained ).toBeTruthy(); expect( state.artContained ).toBeTruthy();
@@ -185,6 +219,9 @@ test( 'desktop grunge stages compose atmosphere, copy, art, and latest in both t
expect( state.atmosphereHidden ).toBe( 'true' ); expect( state.atmosphereHidden ).toBe( 'true' );
} }
await expectNoHorizontalOverflow( page ); await expectNoHorizontalOverflow( page );
} finally {
await context.close();
}
} }
} }
} ); } );
@@ -290,58 +327,162 @@ test( 'latest podcast stacks at 720px and becomes two columns at 721px', async (
} }
} ); } );
test( '200 percent zoom contains Music copy and Podcast card at narrow and wide viewports', async ( { test( '200 percent reflow models physical viewport halving and doubled root text cross-engine', async ( {
page, browser,
} ) => { }, testInfo ) => {
test.setTimeout( 90_000 ); test.setTimeout( 180_000 );
for ( const width of [ 375, 1440 ] ) { for ( const theme of [ 'dark', 'light' ] ) {
await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } ); for ( const physicalWidth of [ 750, 1440 ] ) {
const cssWidth = physicalWidth / 2;
for ( const landing of landings ) { for ( const landing of landings ) {
await page.goto( landing.path ); const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
await page.evaluate( () => { height: physicalWidth === 750 ? 812 : 900,
document.documentElement.style.zoom = '2'; path: landing.path,
theme,
width: cssWidth,
} ); } );
expect( try {
await page.evaluate( () => window.getComputedStyle( document.documentElement ).zoom ), const baselineRootFont = await page.evaluate( () =>
).toBe( '2' ); Number.parseFloat( window.getComputedStyle( document.documentElement ).fontSize ),
const result = await page.locator( landing.root ).evaluate( ( root ) => { );
const readRect = ( element ) => { await page.evaluate( ( doubledRootFont ) => {
const bounds = element.getBoundingClientRect(); document.documentElement.style.fontSize = `${ doubledRootFont }px`;
return { }, baselineRootFont * 2 );
bottom: bounds.bottom, const model = await page.evaluate(
height: bounds.height, ( expectedCssWidth ) => ( {
left: bounds.left, cssViewportWidth: window.innerWidth,
right: bounds.right, doubledRootFont: Number.parseFloat(
top: bounds.top, window.getComputedStyle( document.documentElement ).fontSize,
width: bounds.width, ),
}; stackMediaActive: window.matchMedia( '(max-width: 720px)' ).matches,
}; expectedCssWidth,
} ),
cssWidth,
);
expect( model.cssViewportWidth ).toBe( model.expectedCssWidth );
expect( model.doubledRootFont ).toBe( baselineRootFont * 2 );
expect( model.stackMediaActive ).toBeTruthy();
const result = await page.locator( landing.root ).evaluate( ( root, landingName ) => {
const stage = root.querySelector( '.chrnx-character-stage' ); const stage = root.querySelector( '.chrnx-character-stage' );
const content = stage.querySelector( '.chrnx-character-stage__content' ); const content = stage.querySelector( '.chrnx-character-stage__content' );
const title = root.querySelector( 'h2, h3, .chrnx-podcast-card__title' ); const stageTitle = content.querySelector( 'h2' );
const pageTitle = document.querySelector(
'main.chrnx-entry--page > h1.wp-block-post-title',
);
const card = root.querySelector( '.chrnx-latest-podcast' ); const card = root.querySelector( '.chrnx-latest-podcast' );
const isContained = ( child, parent ) => { const cardTitle = card?.querySelector( '.chrnx-podcast-card__title' );
const childRect = readRect( child ); const unbroken = `https://chrnx.dev/${ 'reflow-safe-token-'.repeat( 18 ) }`;
const parentRect = readRect( parent ); if ( landingName === 'Music' ) {
return childRect.left >= parentRect.left - 1 && childRect.right <= parentRect.right + 1; content.querySelector( 'p:last-of-type' ).textContent += ` ${ unbroken }`;
}; } else {
cardTitle.textContent = unbroken;
}
return { return {
copyContained: isContained( content, stage ), pageTitleClip: pageTitle.scrollWidth - pageTitle.clientWidth,
titleClip: title.scrollWidth - title.clientWidth, stageTitleClip: stageTitle.scrollWidth - stageTitle.clientWidth,
copyClip: content.scrollWidth - content.clientWidth,
cardClip: card ? card.scrollWidth - card.clientWidth : 0, cardClip: card ? card.scrollWidth - card.clientWidth : 0,
cardTitleClip: cardTitle ? cardTitle.scrollWidth - cardTitle.clientWidth : 0,
stageClip: stage.scrollWidth - stage.clientWidth, stageClip: stage.scrollWidth - stage.clientWidth,
cardColumns: card
? window
.getComputedStyle( card.querySelector( '.chrnx-podcast-card__link' ) )
.gridTemplateColumns.split( ' ' ).length
: null,
}; };
} ); }, landing.name );
expect( result.copyContained ).toBeTruthy(); expect( result.pageTitleClip ).toBeLessThanOrEqual( 1 );
expect( result.titleClip ).toBeLessThanOrEqual( 1 ); expect( result.stageTitleClip ).toBeLessThanOrEqual( 1 );
expect( result.copyClip ).toBeLessThanOrEqual( 1 );
expect( result.cardClip ).toBeLessThanOrEqual( 1 ); expect( result.cardClip ).toBeLessThanOrEqual( 1 );
expect( result.cardTitleClip ).toBeLessThanOrEqual( 1 );
expect( result.stageClip ).toBeLessThanOrEqual( 1 ); expect( result.stageClip ).toBeLessThanOrEqual( 1 );
if ( landing.name === 'Podcast' ) {
expect( result.cardColumns ).toBe( 1 );
}
await expectNoHorizontalOverflow( page ); await expectNoHorizontalOverflow( page );
} finally {
await context.close();
}
}
} }
} }
} ); } );
test( 'DOM-only long Podcast copy wraps normally without clipping', async ( { page } ) => { test( 'unbroken Podcast title and excerpt tokens wrap in stack and grid without clipping', async ( {
browser,
}, testInfo ) => {
test.setTimeout( 180_000 );
for ( const theme of [ 'dark', 'light' ] ) {
for ( const width of [ 375, 721, 1440 ] ) {
const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
height: width === 375 ? 812 : 1024,
path: '/podcasts/',
theme,
width,
} );
try {
const state = await page.locator( '.chrnx-latest-podcast' ).evaluate( ( panel ) => {
const link = panel.querySelector( '.chrnx-podcast-card__link' );
const content = panel.querySelector( '.chrnx-podcast-card__content' );
const title = panel.querySelector( '.chrnx-podcast-card__title' );
const excerpt = panel.querySelector( '.chrnx-podcast-card__excerpt' );
const beforeHeight = panel.getBoundingClientRect().height;
const titleToken = `https://chrnx.dev/${ 'title-token-'.repeat( 22 ) }`;
const excerptToken = `sha256:${ '0123456789abcdef'.repeat( 16 ) }`;
title.textContent = titleToken;
excerpt.textContent = excerptToken;
const afterHeight = panel.getBoundingClientRect().height;
const titleStyle = window.getComputedStyle( title );
const excerptStyle = window.getComputedStyle( excerpt );
return {
columns: window.getComputedStyle( link ).gridTemplateColumns.split( ' ' ).length,
contentOverflowWrap: window.getComputedStyle( content ).overflowWrap,
titleOverflowWrap: titleStyle.overflowWrap,
excerptOverflowWrap: excerptStyle.overflowWrap,
titleWordBreak: titleStyle.wordBreak,
excerptWordBreak: excerptStyle.wordBreak,
titleClip: title.scrollWidth - title.clientWidth,
excerptClip: excerpt.scrollWidth - excerpt.clientWidth,
contentClip: content.scrollWidth - content.clientWidth,
linkClip: link.scrollWidth - link.clientWidth,
panelClip: panel.scrollWidth - panel.clientWidth,
beforeHeight,
afterHeight,
linkReadable:
link.tagName === 'A' &&
Boolean( link.getAttribute( 'href' ) ) &&
window.getComputedStyle( link ).visibility === 'visible',
titleLength: titleToken.length,
excerptLength: excerptToken.length,
};
} );
expect( state.titleLength ).toBeGreaterThan( 200 );
expect( state.excerptLength ).toBeGreaterThan( 200 );
expect( state.columns ).toBe( width <= 720 ? 1 : 2 );
expect( state.contentOverflowWrap ).toBe( 'anywhere' );
expect( state.titleOverflowWrap ).toBe( 'anywhere' );
expect( state.excerptOverflowWrap ).toBe( 'anywhere' );
expect( state.titleWordBreak ).toBe( 'normal' );
expect( state.excerptWordBreak ).toBe( 'normal' );
expect( state.titleClip ).toBeLessThanOrEqual( 1 );
expect( state.excerptClip ).toBeLessThanOrEqual( 1 );
expect( state.contentClip ).toBeLessThanOrEqual( 1 );
expect( state.linkClip ).toBeLessThanOrEqual( 1 );
expect( state.panelClip ).toBeLessThanOrEqual( 1 );
expect( state.afterHeight ).toBeGreaterThan( state.beforeHeight );
expect( state.linkReadable ).toBeTruthy();
await expectNoHorizontalOverflow( page );
} finally {
await context.close();
}
}
}
} );
test( 'DOM-only long Podcast prose preserves its 28ch column without clipping', async ( {
page,
} ) => {
for ( const width of [ 375, 1440 ] ) { for ( const width of [ 375, 1440 ] ) {
await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } ); await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } );
await page.goto( '/podcasts/' ); await page.goto( '/podcasts/' );
@@ -391,7 +532,7 @@ test( 'DOM-only long Podcast copy wraps normally without clipping', async ( { pa
if ( state.columns === 2 ) { if ( state.columns === 2 ) {
expect( state.contentWidth ).toBeGreaterThanOrEqual( state.probeWidth - 1 ); expect( state.contentWidth ).toBeGreaterThanOrEqual( state.probeWidth - 1 );
} }
expect( state.overflowWrap ).toBe( 'normal' ); expect( state.overflowWrap ).toBe( 'anywhere' );
expect( state.wordBreak ).toBe( 'normal' ); expect( state.wordBreak ).toBe( 'normal' );
expect( state.titleClip ).toBeLessThanOrEqual( 1 ); expect( state.titleClip ).toBeLessThanOrEqual( 1 );
expect( state.excerptClip ).toBeLessThanOrEqual( 1 ); expect( state.excerptClip ).toBeLessThanOrEqual( 1 );
@@ -438,15 +579,19 @@ const immutableSurfaces = [
]; ];
test( 'Projects and About assets, copy, layering, and geometry remain immutable', async ( { test( 'Projects and About assets, copy, layering, and geometry remain immutable', async ( {
page, browser,
} ) => { }, testInfo ) => {
test.setTimeout( 90_000 ); test.setTimeout( 180_000 );
for ( const theme of [ 'dark', 'light' ] ) { for ( const theme of [ 'dark', 'light' ] ) {
await setTheme( page, theme );
for ( const width of [ 375, 1440 ] ) { for ( const width of [ 375, 1440 ] ) {
await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } );
for ( const surface of immutableSurfaces ) { for ( const surface of immutableSurfaces ) {
await page.goto( surface.path ); const { context, page } = await openIsolatedThemedPage( browser, testInfo, {
height: width === 375 ? 812 : 900,
path: surface.path,
theme,
width,
} );
try {
const root = page.locator( surface.root ); const root = page.locator( surface.root );
for ( const heading of surface.headings ) { for ( const heading of surface.headings ) {
await expect( root.getByRole( 'heading', { name: heading, exact: true } ) ).toHaveCount( await expect( root.getByRole( 'heading', { name: heading, exact: true } ) ).toHaveCount(
@@ -503,7 +648,8 @@ test( 'Projects and About assets, copy, layering, and geometry remain immutable'
).length, ).length,
artRatio: artRect.width / stageRect.width, artRatio: artRect.width / stageRect.width,
artFrameContained: contained( artRect, stageRect ), artFrameContained: contained( artRect, stageRect ),
artImageContained: contained( imageRect, artRect ) && contained( imageRect, stageRect ), artImageContained:
contained( imageRect, artRect ) && contained( imageRect, stageRect ),
overflow: stage.scrollWidth - stage.clientWidth, overflow: stage.scrollWidth - stage.clientWidth,
}; };
} ); } );
@@ -517,6 +663,9 @@ test( 'Projects and About assets, copy, layering, and geometry remain immutable'
} }
expect( state.overflow ).toBeLessThanOrEqual( 1 ); expect( state.overflow ).toBeLessThanOrEqual( 1 );
await expectNoHorizontalOverflow( page ); await expectNoHorizontalOverflow( page );
} finally {
await context.close();
}
} }
} }
} }
+2 -2
View File
@@ -583,7 +583,7 @@ test( 'latest podcast owns a content-aware 720px card contract', () => {
); );
assert.match( assert.match(
podcast, podcast,
/\.chrnx-podcast-card__content\s*\{[\s\S]*?min-width:\s*0;[\s\S]*?overflow-wrap:\s*normal;/, /\.chrnx-podcast-card__content\s*\{[\s\S]*?min-width:\s*0;[\s\S]*?overflow-wrap:\s*anywhere;/,
); );
assert.match( assert.match(
podcast, podcast,
@@ -591,7 +591,7 @@ test( 'latest podcast owns a content-aware 720px card contract', () => {
); );
assert.match( assert.match(
podcast, podcast,
/\.chrnx-podcast-card__title,[\s\S]*?\.chrnx-podcast-card__excerpt,[\s\S]*?\.chrnx-podcast-card__badge\s*\{[\s\S]*?overflow-wrap:\s*normal;[\s\S]*?word-break:\s*normal;/, /\.chrnx-podcast-card__title,[\s\S]*?\.chrnx-podcast-card__excerpt,[\s\S]*?\.chrnx-podcast-card__badge\s*\{[\s\S]*?overflow-wrap:\s*anywhere;[\s\S]*?word-break:\s*normal;/,
); );
assert.match( assert.match(
podcast, podcast,