From fdc3079d1692866421e16abf141da7e54186c14b Mon Sep 17 00:00:00 2001 From: Adam Alston Date: Wed, 20 Aug 2025 23:26:06 -0400 Subject: [PATCH 1/2] fix(navigation): resolve wait on canceled requests --- cli/CHANGELOG.md | 4 +++ .../cypress/e2e/commands/navigation.cy.js | 22 +++++++++++++ packages/driver/src/cy/commands/navigation.ts | 31 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 891f19ac89f..cf7b749e2cd 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -3,6 +3,10 @@ _Released 08/26/2025 (PENDING)_ +**Bugfixes:** + +* Fixed an issue where `cy.wait('@alias')` could time out when the underlying network request was canceled by navigation (e.g., `cy.visit`, `cy.reload`). Fixes [#19326](https://github.com/cypress-io/cypress/issues/19326). + **Dependency Updates:** - Upgraded `tar` from `6.1.5` to `6.2.1`. Addressed in [#32229](https://github.com/cypress-io/cypress/pull/32229). diff --git a/packages/driver/cypress/e2e/commands/navigation.cy.js b/packages/driver/cypress/e2e/commands/navigation.cy.js index 3b9e9de6a22..b0415b402bb 100644 --- a/packages/driver/cypress/e2e/commands/navigation.cy.js +++ b/packages/driver/cypress/e2e/commands/navigation.cy.js @@ -1878,6 +1878,28 @@ describe('src/cy/commands/navigation', () => { }) }) }) + + it('should resolve wait for a request canceled by navigation', () => { + const alias = crypto.randomUUID() + + cy.intercept(/jsonplaceholder.cypress.io/).as(alias) + + cy.visit('https://example.cypress.io/commands/network-requests') + cy.get('.network-btn').click() + + cy.visit('https://example.cypress.io/commands/network-requests') + cy.wait(`@${alias}`).then((interception) => { + const actual = JSON.parse( + JSON.stringify(interception, (_, value) => value), + ) + + cy.wrap(actual).should('deep.equal', { + ...actual, + state: 'Errored', + error: { ...interception.error }, + }) + }) + }) }) // TODO(webkit): fix+unskip for webkit release diff --git a/packages/driver/src/cy/commands/navigation.ts b/packages/driver/src/cy/commands/navigation.ts index 4ff70ec2f6a..c173bc8e384 100644 --- a/packages/driver/src/cy/commands/navigation.ts +++ b/packages/driver/src/cy/commands/navigation.ts @@ -176,6 +176,18 @@ const pageLoading = (bool, Cypress, state) => { Cypress.action('app:page:loading', bool) } +const markRequestAsCancelled = (request: any) => { + if ( + request && + request.state === 'Received' && + !request.response && + !request.error + ) { + request.state = 'Errored' + request.error = new Error('Request was cancelled due to navigation.') + } +} + const stabilityChanged = async (Cypress, state, config, stable) => { debug('stabilityChanged:', stable) @@ -188,6 +200,25 @@ const stabilityChanged = async (Cypress, state, config, stable) => { return } + // Mark inflight requests as canceled at navigation start. + try { + const routes = state('routes') ?? {} + + _.forEach(routes, ({ requests }) => { + _.forEach(requests, markRequestAsCancelled) + }) + + const aliasedRequests = state('aliasedRequests') ?? [] + + aliasedRequests.forEach(({ request }) => { + markRequestAsCancelled(request) + }) + } catch (_) { + // TODO: Should I use `$errUtils.logError` or another method from + // `$errUtils` here? Alternatively, should I do nothing, since canceled + // requests aren't necessarily a problem in Cypress? + } + // if we purposefully just caused the page to load // (and thus instability) don't log this out if (knownCommandCausedInstability) { From f670c4122d6e2987769b1702b6c503c2b5049eb8 Mon Sep 17 00:00:00 2001 From: Bill Glesias Date: Fri, 24 Oct 2025 14:37:34 -0400 Subject: [PATCH 2/2] update changelog --- cli/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 3d3598aa00f..d4d9353fbc4 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -12,6 +12,7 @@ _Released 10/20/2025 (PENDING)_ - Fixed an issue where grouped command text jumps up and down when expanding and collapsing in the command log. Addressed in [#32757](https://github.com/cypress-io/cypress/pull/32757). - Fixed an issue where command snapshots were not correctly displayed in Studio. Addressed in [#32808](https://github.com/cypress-io/cypress/pull/32808). - Fixed an issue with grouped console prop items having a hard to read blue color in the console log and duplicate `:` characters being displayed. Addressed in [#32776](https://github.com/cypress-io/cypress/pull/32776). +- Fixed an issue where `cy.wait('@alias')` could time out when the underlying network request was canceled by navigation (e.g., `cy.visit`, `cy.reload`). Fixes [#19326](https://github.com/cypress-io/cypress/issues/19326). **Misc:** @@ -126,7 +127,6 @@ _Released 09/02/2025_ - Fixed an issue where the open Studio button would incorrectly show for component tests. Addressed in [#32315](https://github.com/cypress-io/cypress/pull/32315). - Fixed an issue where the TypeScript compiler wasn't being resolved correctly when `@cypress/webpack-batteries-included-preprocessor` was used as a standalone package. Fixes [#32338](https://github.com/cypress-io/cypress/issues/32338). - Fixed an issue where `tsx` was not being loaded correctly into the Cypress configuration process due to spaces being present in the path. Fixes [#32398](https://github.com/cypress-io/cypress/issues/32398). -* Fixed an issue where `cy.wait('@alias')` could time out when the underlying network request was canceled by navigation (e.g., `cy.visit`, `cy.reload`). Fixes [#19326](https://github.com/cypress-io/cypress/issues/19326). **Misc:**