Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'undefined') in historyNavigationTriggeredHashChange #20539

Closed
kaiyoma opened this issue Mar 9, 2022 · 12 comments · Fixed by #20948
Labels
type: regression A bug that didn't appear until a specific Cy version release

Comments

@kaiyoma
Copy link

kaiyoma commented Mar 9, 2022

Current behavior

We have a Cypress test which tests UI navigation by clicking links, then using the browser's back button to pop the history stack. When running this test in Cypress 9.5.0, we get a stack trace from Cypress code:

Uncaught TypeError: Cannot read properties of undefined (reading 'undefined')
    at historyNavigationTriggeredHashChange (cypress_runner.js:166581:101)
    at HTMLIFrameElement.<anonymous> (cypress_runner.js:173017:111)
    at HTMLIFrameElement.dispatch (cypress_runner.js:113217:27)
    at HTMLIFrameElement.elemData.handle (cypress_runner.js:113025:28)

Desired behavior

No stack trace.

Test code to reproduce

N/A

Cypress Version

9.5.0

Other

No response

@davidmunechika davidmunechika added the stage: needs information Not enough info to reproduce the issue label Mar 10, 2022
@davidmunechika
Copy link
Contributor

Can you include a reproducible example or example repo so we can reproduce your issue? Unfortunately we will have to close this issue as there is not enough information to reproduce the problem. This does not mean that your issue is not happening - it just means that we do not have a path to move forward.

Please comment in this issue with a reproducible example and we will consider reopening the issue. Thanks!

@kaiyoma
Copy link
Author

kaiyoma commented Mar 10, 2022

Unfortunately that won't be possible since I have complicated tests for a complicated proprietary app. However, I can repro this problem 100% of the time locally, so I'm happy to gather extra debugging information for you if you give me some guidance.

@DiegoMcDipster
Copy link

I had this same issue yesterday and I now have it working. For me it was because of one of two things:

  1. because of cookies being deleted at the start of each test.
    I had:
it('first test', () => { runs and loads cookies})
it('second test', () => { reads from cookies and does stuff})

I have it working now by merging the two tests, like so:

it('first + second test', () => { 
runs and loads cookies
reads from cookies and does stuff
})

Or... 2. Cypress is sometimes flakey when moving between pages, spread across tests. A bit of background: I'm using NextJs and between the tests I'm moving from one NextJs page to another and back. Putting these transitions into one test solves the problem. (I had read something about it. But I can no longer find it. Sorry.)

Anyway, I hope this helps you get closer to a solution! Happy hacking!

@davidmunechika davidmunechika added stage: awaiting response Potential fix was proposed; awaiting response and removed stage: needs information Not enough info to reproduce the issue labels Mar 11, 2022
@kaiyoma
Copy link
Author

kaiyoma commented Mar 11, 2022

Yes, this is similar to what I encountered too. My test suite also moves across a lot of pages via several tests, and then pops the entire browser stack by using the browser's back button (in a separate test).

The test passes just fine in our CI, which is running Chrome 95 on Linux, but the test fails for me locally on my laptop, which is running Chrome 99 on Windows 10. Cypress 9.5.0 is being used in both cases. It's unclear if the OS version or Chrome version is causing a difference in behavior.

I suppose if I start running into this issue in our CI in the future, I'll try combining all the test logic into a single test and see if that helps. Thanks @DiegoMcDipster!

@kaiyoma
Copy link
Author

kaiyoma commented Apr 1, 2022

I'm seeing this a lot more in Chrome 100, both in Windows 10 and Linux. My test can actually repro this 100% of the time in Cypress 9.5.0. I think this should be reopened.

@kaiyoma
Copy link
Author

kaiyoma commented Apr 1, 2022

@DiegoMcDipster I implemented your suggestion (combining all tests into one) and it fixed the problem! Hopefully this helps others who stumble upon this. There's a workaround available but the root issue should still be fixed in Cypress.

@tstark2
Copy link

tstark2 commented Apr 1, 2022

I'm having this issue too, but it's not only in cypress 9.5.x, I'm seeing it all the way back to version 9.2. 9.1.1 works as expected. That said, I think this may be related to Chrome 100. In 9.5.3 I can run the same tests in FIrefox and they all pass. Hopefully that helps.

@pnjihia
Copy link

pnjihia commented Apr 4, 2022

Experiencing a similar issue with tests that involve page transitions. This was with both 9.5.3 and 9.5.2. The previous version (9.1.0) worked. The workaround was to suppress the exception, but this could hide other valid issues, so not a good solution. I hope we get a fix for this.

Cypress.on('uncaught:exception', (err, runnable) => {
  return false;
});

@mr-short
Copy link
Contributor

mr-short commented Apr 6, 2022

This is still happening in Cypress 9.5.3. It is a result of trying to do cy.url() during a url/page change.

After digging into the cypress_runner.js and historyNavigationTriggeredHashChange function, I found this to be the cause:

  const urls = state('urls');
  const urlPosition = state('urlPosition');
  const currentUrl = _cypress_location__WEBPACK_IMPORTED_MODULE_0__[/* $Location */ "a"].create(urls[urlPosition]);

Both urls and urlPosition is undefined, which explains the error message and proves this a Cypress bug and not within the application.

@emilyrohrbough
Copy link
Member

@mr-short / @tstark2 / @pnjihia / @kaiyoma / @DiegoMcDipster

This issue appears to be a duplicate of #19749.

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: pending release and removed stage: awaiting response Potential fix was proposed; awaiting response stage: needs review The PR code is done & tested, needs review labels Apr 6, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 8, 2022

The code for this is done in cypress-io/cypress#20948, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@emilyrohrbough emilyrohrbough added the type: regression A bug that didn't appear until a specific Cy version release label Apr 11, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 11, 2022

Released in 9.5.4.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v9.5.4, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Apr 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: regression A bug that didn't appear until a specific Cy version release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants