Skip to content

Commit 703c097

Browse files
committed
build(ssg): optional retry pass for flaky routes (PRERENDER_RETRY=1)
Some app pages and series episodes occasionally fail the 8s render gate under concurrent load. Gate a sequential retry pass behind the PRERENDER_RETRY=1 env var so the default build stays fast while allowing a completeness-first run when needed.
1 parent dc0aff4 commit 703c097

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

scripts/prerender-crawl.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const CONCURRENCY = Number(process.env.PRERENDER_CONCURRENCY) || 6;
1212
const PAGE_TIMEOUT = 30000;
1313
const RENDER_SETTLE_MS = 300;
1414
const SELECTOR_TIMEOUT = 8000;
15+
const RETRY = process.env.PRERENDER_RETRY === '1';
1516

1617
function routeToFile(route) {
1718
if (route === '/') return join(DIST, 'index.html');
@@ -98,6 +99,30 @@ async function main() {
9899
});
99100
await Promise.all(workers);
100101

102+
if (RETRY) {
103+
const flaky = results
104+
.filter((r) => r.skipped && /within \d+ms|empty root/.test(r.skipped))
105+
.map((r) => r.route);
106+
if (flaky.length) {
107+
console.log(`\nprerender-crawl: retrying ${flaky.length} flaky route(s) sequentially...`);
108+
const retryResults = new Map();
109+
for (const route of flaky) {
110+
const r = await crawlOne(browser, url, route);
111+
retryResults.set(route, r);
112+
if (r.bytes) console.log(` . ${route} (retry: ${r.bytes} bytes, ${r.errors} console errors)`);
113+
else if (r.skipped) console.log(` - ${route}: retry ${r.skipped}`);
114+
else if (r.error) console.log(` x ${route}: retry ${r.error}`);
115+
}
116+
for (let i = 0; i < results.length; i++) {
117+
const r = results[i];
118+
if (retryResults.has(r.route)) {
119+
const next = retryResults.get(r.route);
120+
if (next.bytes || next.error) results[i] = next;
121+
}
122+
}
123+
}
124+
}
125+
101126
await browser.close();
102127
await new Promise((resolve) => server.httpServer.close(resolve));
103128

0 commit comments

Comments
 (0)