Repository navigation
Are aliased elements returned without re-querying in some cases? #33806
They could not contradict each other because the same section mentions
So maybe the existing reference is used if the element is not completely removed? And we are sometimes getting detached elements despite using correct chaining (and without But https://docs.cypress.io/app/references/migration-guide#Behavior-Changes-in-Alias-Resolution seems to say 2 is in fact correct without this qualification:
|
Replies: 2 comments 1 reply
|
@{owner=cypress-io; name=cypress; number=33806; body=My reading is:
So these two docs are reconcilable: the alias name is looked up first, but for a DOM/query alias Cypress resolves it by replaying the query chain, not by handing you the exact old node forever. Where detached-element errors still happen is usually after you got the alias, when an action causes the DOM to re-render and you keep chaining on the stale subject: cy.get('li.todo').first().as('firstTodo')
cy.get('@firstTodo').click() // click may trigger re-render
cy.get('@firstTodo').should('contain', 'done') // re-query: goodvs cy.get('@firstTodo')
.click()
.should('contain', 'done') // same chain, stale subject risk after clickIf the element is expected to change/remount, I’d split the chain and re-query after the DOM-changing action. And if you truly want a snapshot, use: cy.get('li.todo').first().as('firstTodo', { type: 'static' })So short answer: no, I would not rely on aliased DOM elements being returned “without re-querying” in modern Cypress.}.body |
I actually wanted to know if I can rely on them always being re-queried (which was my understanding before noticing the first point).
By "And we are sometimes getting detached elements despite using correct chaining" I meant that:
Still, the last time it happened was quite a bit of time ago and couldn't be reproduced now. |
|
I made some updates to the docs here that hopefully clears up some of the confusion here: cypress-io/cypress-documentation#6539 |
I made some updates to the docs here that hopefully clears up some of the confusion here: cypress-io/cypress-documentation#6539