Cypress reload issue, URL keeps reloading

I am facing a strange Cypress reload issue. When I start a test for a specific URL, the page keeps reloading in an infinite loop.

Has anyone else experienced this? What could be causing Cypress to reload the page endlessly during a test run?

I ran into a similar Cypress reload loop when testing a login flow. Turned out it was due to a window.location.reload() being triggered in the app when certain session data wasn’t found.

Cypress clears cookies and localStorage between tests by default, so my app thought it was in a bad state and kept reloading.

I fixed it by setting the necessary auth tokens using cy.setCookie() before hitting the page.

Hope this was simple :slight_smile:

Yes, I’ve dealt with the infinite Cypress reload issue too, and in my case, it was a service worker problem.

The app was registering a service worker that detected Cypress’s automation headers and kept triggering reloads.

Disabling service worker registration in test mode (using an env check like if (process.env.NODE_ENV !== 'test')) solved it for us.

Had the same thing last month. The culprit was a useEffect hook in React that was firing a redirect when it detected Cypress headers (like __cypress_xhr__).

Cypress kept reloading, React kept redirecting, loop city. What worked for me was checking navigator.webdriver in the app code to avoid running redirects when tests were running.

That finally stopped the Cypress reload cycle. Hope this helps