fix(web): recover pre-render boot failures
This commit is contained in:
@@ -8,6 +8,7 @@ const mileageWorkers = assets.filter((name) => /^mileageExport\.worker-[\w-]+\.j
|
||||
const monitorAssets = assets.filter((name) => /^MonitorPage-[\w-]+\.js$/.test(name));
|
||||
const runtimeConfig = readFileSync(resolve(process.cwd(), 'dist/app-config.js'), 'utf8');
|
||||
const safeRuntimeTemplate = readFileSync(resolve(process.cwd(), 'public/app-config.example.js'), 'utf8');
|
||||
const builtIndex = readFileSync(resolve(process.cwd(), 'dist/index.html'), 'utf8');
|
||||
const releaseManifest = readFileSync(resolve(process.cwd(), 'dist/.release-assets'), 'utf8').split(/\r?\n/).filter(Boolean);
|
||||
|
||||
if (excelAssets.length !== 1) {
|
||||
@@ -22,6 +23,16 @@ if (monitorAssets.length !== 1) {
|
||||
if (runtimeConfig !== safeRuntimeTemplate) {
|
||||
throw new Error('production dist/app-config.js must match the credential-free runtime template');
|
||||
}
|
||||
if (!builtIndex.includes('id="platform-boot"')
|
||||
|| !builtIndex.includes('vehicle-platform:ready')
|
||||
|| !builtIndex.includes('window.setTimeout(fail, 10_000)')) {
|
||||
throw new Error('production index must retain the static boot recovery boundary');
|
||||
}
|
||||
const mainAsset = builtIndex.match(/<script[^>]+type="module"[^>]+src="\/assets\/([^"/]+\.js)"/)?.[1];
|
||||
if (!mainAsset || !assets.includes(mainAsset)
|
||||
|| !readFileSync(resolve(assetsDirectory, mainAsset), 'utf8').includes('vehicle-platform:ready')) {
|
||||
throw new Error('production entry must retain the React boot-ready handshake');
|
||||
}
|
||||
if (releaseManifest.length !== assets.length || releaseManifest.some((name, index) => name !== [...assets].sort()[index])) {
|
||||
throw new Error('production dist/.release-assets must list every generated asset exactly once in sorted order');
|
||||
}
|
||||
@@ -50,4 +61,4 @@ if (monitorBytes > 35_000) {
|
||||
throw new Error(`monitor critical-path asset exceeds 35000 bytes: ${monitorBytes}`);
|
||||
}
|
||||
const qrBytes = statSync(resolve(assetsDirectory, qrAssets[0])).size;
|
||||
process.stdout.write(`web_build_gate=ok release_assets=${releaseManifest.length} exceljs_assets=1 exceljs_bytes=${excelBytes} mileage_workers=1 worker_bytes=${workerBytes} monitor_bytes=${monitorBytes} qr_deferred=1 qr_bytes=${qrBytes} runtime_config_sanitized=1\n`);
|
||||
process.stdout.write(`web_build_gate=ok release_assets=${releaseManifest.length} exceljs_assets=1 exceljs_bytes=${excelBytes} mileage_workers=1 worker_bytes=${workerBytes} monitor_bytes=${monitorBytes} qr_deferred=1 qr_bytes=${qrBytes} runtime_config_sanitized=1 boot_recovery=1\n`);
|
||||
|
||||
Reference in New Issue
Block a user