fix(ci): accept hydrated documents with cancelled preload requests
creative workspace review checks / verify-deployed-canvas (pull_request) Successful in 1m7s
creative workspace review checks / verify (pull_request) Successful in 26m21s

This commit is contained in:
2026-11-01 22:14:37 +08:00
parent e36b8aea6c
commit 150e4b3af8
2 changed files with 24 additions and 11 deletions
+14 -7
View File
@@ -38,8 +38,8 @@ export async function navigateBrandDocument(navigate, url, now = Date.now) {
* @param {boolean} reload
*/
export async function visitBrowserDocument(page, url, reload = false) {
const started = Date.now();
const response = await navigateBrandDocument(async timeout => {
return navigateBrandDocument(async timeout => {
const started = Date.now();
const scripts = new Set(), failures = [];
const requested = request => { if (request.resourceType() === 'script') scripts.add(request); };
const failed = request => { if (scripts.has(request)) failures.push(request.failure()?.errorText || 'unknown script failure'); };
@@ -47,15 +47,22 @@ export async function visitBrowserDocument(page, url, reload = false) {
page.on('requestfailed', failed);
try {
const response = await (reload ? page.reload({waitUntil: 'domcontentloaded', timeout}) : page.goto(url, {waitUntil: 'domcontentloaded', timeout}));
if (response?.ok() && failures.length) throw new Error('Document bootstrap script request failed: ' + failures.join('; '));
if (response?.ok()) {
const remaining = timeout - (Date.now() - started);
if (remaining <= 0) throw new Error('Document hydration budget exhausted: ' + url);
try {
// A cancelled script may be a preload duplicate. Hydration is the
// authority; recover only when cancellation actually blocks startup.
await page.locator('button[data-theme-ready="true"]').first().waitFor({timeout: failures.length ? Math.min(5000, remaining) : remaining});
} catch (error) {
if (failures.length) throw new Error('Document bootstrap script request failed: ' + failures.join('; '), {cause: error});
throw error;
}
}
return response;
} finally {
page.off('request', requested);
page.off('requestfailed', failed);
}
}, url);
const remaining = 60000 - (Date.now() - started);
if (remaining <= 0) throw new Error('Document hydration budget exhausted: ' + url);
await page.locator('button[data-theme-ready="true"]').first().waitFor({timeout: remaining});
return response;
}