fix(B04): prevent image URI flash across initial render and detail remounts

This commit is contained in:
Codex committed 2026-10-21 15:15:29 +09:00
1 parent 0b613e522d
commit 342820690f
7 files changed
+217 -24

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
/** Optional, isolated own-component Electron frame probe; never launches the user's app.
* Build first: node scripts/test-image-lifecycle.mjs --build-only
* Then: electron scripts/verify-b04-image-native.cjs <output-directory>
* Requires a permitted graphical environment. Never pass --no-sandbox. */
const {app,BrowserWindow,session}=require('electron')
const fs=require('node:fs'),path=require('node:path'),os=require('node:os')
const fixture=path.resolve(process.argv[2]||'')
if(!process.argv[2]||!fs.existsSync(path.join(fixture,'index.html')))throw Error('Supply build-only fixture directory')
const profile=fs.mkdtempSync(path.join(os.tmpdir(),'ycode-b04-native-'))
app.setPath('userData',profile)
let timer,win,finished=false
function finish(error,report){
if(finished)return;finished=true;clearTimeout(timer)
const result={result:error?'FAIL':'PASS',error:error?String(error):undefined,report,limits:'Synthetic own-component Electron fixture, not the installed application or original reference UI.'}
fs.writeFileSync(path.join(fixture,'native-report.json'),JSON.stringify(result,null,2))
console.log(JSON.stringify({result:result.result,error:result.error,output:path.join(fixture,'native-report.json')}))
if(win&&!win.isDestroyed())win.destroy()
app.exit(error?1:0)
}
app.whenReady().then(async()=>{
session.defaultSession.webRequest.onBeforeRequest((details,callback)=>callback({cancel:!['file:','data:','blob:','devtools:'].some(p=>details.url.startsWith(p))}))
win=new BrowserWindow({width:1000,height:800,show:true,webPreferences:{nodeIntegration:false,contextIsolation:true,sandbox:true}})
win.webContents.on('render-process-gone',(_,details)=>finish(Error('Renderer gone: '+details.reason)))
timer=setTimeout(()=>finish(Error('Bounded native probe timed out after 20s')),20000)
await win.loadFile(path.join(fixture,'index.html'))
const report=await win.webContents.executeJavaScript(`new Promise((resolve,reject)=>{const check=()=>{if(window.__b04Error)return reject(Error(window.__b04Error));if(window.__b04Report)return resolve(window.__b04Report);setTimeout(check,25)};check()})`)
if(!report.samples.some(s=>s.height>0))throw Error('No nonzero native layout measured')
if(report.samples.some(s=>s.textLength>1000||s.height>2000))throw Error('Unexpected address-sized text/height spike')
finish(null,report)
}).catch(error=>finish(error))