From e7a7cdc6b9fb69cf1426c5f94cd79371787a262a Mon Sep 17 00:00:00 2001 From: Jonathan Sykes Date: Thu, 8 Oct 2026 08:50:51 +0800 Subject: [PATCH] Preload classic layout CSS before the blocking head loader --- frontend/index.html | 2 ++ frontend/shell-consistency.test.js | 10 ++++++++++ server/static-delivery.test.js | 5 +++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/index.html b/frontend/index.html index ead66fd..682325e 100755 --- a/frontend/index.html +++ b/frontend/index.html @@ -20,6 +20,8 @@ + + diff --git a/frontend/shell-consistency.test.js b/frontend/shell-consistency.test.js index bbdfbff..8302dd8 100644 --- a/frontend/shell-consistency.test.js +++ b/frontend/shell-consistency.test.js @@ -70,6 +70,8 @@ test('only core scripts and styles remain eager; native fallback and active layo const {groups}=JSON.parse(readFileSync(join(__dirname,'assets.json'),'utf8')); const background=new Set(Object.values(groups).filter(g=>g.background).flatMap(g=>g.files)); for(const match of html.matchAll(/<(?:script\b[^>]*\bsrc|link\b[^>]*\bhref)="([^"]+)"/gi)) { + // A style preload discovers bytes without applying or blocking another layout. + if(match[0].includes('rel="preload"'))continue; const path='/'+match[1].replace(/^\//,'').split(/[?#]/)[0]; assert.ok(!background.has(path),`${path} is not eager`); } @@ -88,3 +90,11 @@ test('layout-independent visibility and transport defaults stay in eager CSS',() for(const selector of ['.stg-overlay','.deck-chips','.np-btn.done .i-save','.sleep-status .sl-ic','.ab-group','.mc-tune'])assert.ok(shared.includes(selector)); assert.ok(html.includes('href="layout-base.css"')); }); + + +test('classic first-visit style preload is discovered before the head loader without applying another layout',()=>{ + const preload=html.match(/]*rel="preload"[^>]*href="theme-classic.css"[^>]*as="style"[^>]*>/); + assert.ok(preload,'classic stylesheet has an early preload'); + assert.ok(html.indexOf(preload[0])]*rel="stylesheet"[^>]*href="theme-classic.css"/.test(html),'the selected layout remains parser-applied by the loader'); +}); diff --git a/server/static-delivery.test.js b/server/static-delivery.test.js index ed0661e..e54ab5b 100644 --- a/server/static-delivery.test.js +++ b/server/static-delivery.test.js @@ -13,7 +13,7 @@ mkdirSync(publicDir); mkdirSync(dataDir); mkdirSync(join(publicDir, 'fonts')); mkdirSync(join(publicDir, 'icons')); -writeFileSync(join(publicDir, 'index.html'), ''); +writeFileSync(join(publicDir, 'index.html'), ''); writeFileSync(join(publicDir, 'app.css'), 'body{}'); writeFileSync(join(publicDir, 'app.js'), 'window.app=true;'); writeFileSync(join(publicDir, 'root.css'), 'body{color:red}'); @@ -99,7 +99,8 @@ describe('static delivery characterization', () => { const html = await index.text(); const { buildTag, files } = await (await fetch(`${server.base}/api/manifest`)).json(); expect(html).toContain(``); - expect(html).toContain(`href="app.css?v=${files['/app.css'].h}"`); + expect(html).toContain(``); + expect(html.match(new RegExp('app\\.css\\?v='+files['/app.css'].h,'g'))).toHaveLength(2); expect(html).toContain(`src="app.js?v=${files['/app.js'].h}"`); expect(html).toContain('https://cdn.example/x.js'); expect(html).toContain(`href="/root.css?v=${files['/root.css'].h}"`);