From eb30ef71f926b84786ccd5d81b97cb186de8d751 Mon Sep 17 00:00:00 2001 From: Stefan de Vogelaere Date: Sun, 18 Jan 2026 15:54:24 +0100 Subject: [PATCH] fix: prevent response disposal race condition in E2E test Wrap route.fetch() and response.json() in try/catch blocks to handle cases where the response is disposed before it can be accessed. Falls back to route.continue() to let the original request proceed normally. This fixes the intermittent "Response has been disposed" error in open-existing-project.spec.ts that occurs due to timing issues in CI. --- .../projects/open-existing-project.spec.ts | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/apps/ui/tests/projects/open-existing-project.spec.ts b/apps/ui/tests/projects/open-existing-project.spec.ts index cd9beb98..0e3cb789 100644 --- a/apps/ui/tests/projects/open-existing-project.spec.ts +++ b/apps/ui/tests/projects/open-existing-project.spec.ts @@ -84,18 +84,24 @@ test.describe('Open Project', () => { // Intercept settings API BEFORE any navigation to prevent restoring a currentProject // AND inject our test project into the projects list await page.route('**/api/settings/global', async (route) => { - const response = await route.fetch(); - // Immediately consume the body to prevent disposal issues - const bodyPromise = response.body(); - const status = response.status(); - const headers = response.headers(); - const body = await bodyPromise; + let response; + try { + response = await route.fetch(); + } catch { + // If fetch fails, continue with original request + await route.continue(); + return; + } + let json; try { - json = JSON.parse(body.toString()); + json = await response.json(); } catch { - json = {}; + // If response is disposed, continue with original request + await route.continue(); + return; } + if (json.settings) { // Remove currentProjectId to prevent restoring a project json.settings.currentProjectId = null; @@ -115,11 +121,7 @@ test.describe('Open Project', () => { json.settings.projects = [testProject, ...existingProjects]; } } - await route.fulfill({ - status: status, - headers: headers, - json, - }); + await route.fulfill({ response, json }); }); // Now navigate to the app