Skip to content

Cypress hangs when wrapping an object containing circular references. #24715

@higamaya

Description

@higamaya

Current behavior

Cypress hangs when calling cy.wrap() with an object containing circular references.

Desired behavior

Do not hang.

Test code to reproduce

The code to reproduce this issue is as follows.

class Node {
  parent;
  children = [];

  appendChild(child) {
    child.parent = this;
    this.children.push(child);
    return child;
  }
}

describe("Reproduce the Cypress's issue", () => {
  it("Wrap an object containing circular references", () => {
    const rootNode = new Node();
    rootNode.appendChild(new Node()).appendChild(new Node());
    cy.wrap(rootNode);
    cy.visit("https://example.cypress.io/");
  })
})

The actual code when I encountered the problem was more complex, and at first I did not know what the problem was. So I reduced my code while keeping the problem reproducible and finally arrived at the minimal code shown above.

When I comment out the code child.parent = this; inside appendChild() method, the problem no longer reproduces, so I think circular references might be the cause of the problem. However, this does not mean that circular references is a sufficient condition, as adding a new field to Node class would prevent the problem from being reproduced while circular references still remain.

The entire repro environment can be found in the repository below.
https://github.com/higamaya/cypress-issue-20221117

Cypress Version

v11.1.0, v10.11.0

Node version

v18.12.1

Operating System

Microsoft Windows 10 Pro 10.0.19045

Debug Logs

No response

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    E2EIssue related to end-to-end testingTriagedIssue has been routed to backlog. This is not a commitment to have it prioritized by the team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions