From 3c348a9972de40e68ff524c2401d9edebc38a2bb Mon Sep 17 00:00:00 2001 From: Jaycie Brown Date: Wed, 2 Sep 2026 17:44:16 +0100 Subject: [PATCH 1/5] Attempt My Gameboards VRT fix --- cypress/support/commands.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cypress/support/commands.tsx b/cypress/support/commands.tsx index d4bb345849..1b6f778d97 100644 --- a/cypress/support/commands.tsx +++ b/cypress/support/commands.tsx @@ -63,11 +63,14 @@ import {store} from "../../src/app/state"; import {createBrowserRouter, createRoutesFromElements, Route, To} from "react-router"; import { RouterProvider } from 'react-router-dom'; import { ACTION_TYPE } from '../../src/app/services'; +import {v4 as uuid_v4} from "uuid"; Cypress.Commands.add('mountWithStoreAndRouter', (component, routes, initialRoute=routes?.[0], user, mountOptions) => { + const uuid = uuid_v4(); + const router = createBrowserRouter(createRoutesFromElements(<> {routes?.length - ? routes.map(route => ) + ? routes.map(route => ) : } )); @@ -80,7 +83,7 @@ Cypress.Commands.add('mountWithStoreAndRouter', (component, routes, initialRoute mount( - + , mountOptions ); From a50006f6ccb498f09714581ef0c37cc998024e68 Mon Sep 17 00:00:00 2001 From: Jaycie Brown Date: Thu, 3 Sep 2026 10:10:28 +0100 Subject: [PATCH 2/5] Add unique React key to all Cypress CBR routes --- cypress/support/commands.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/support/commands.tsx b/cypress/support/commands.tsx index 1b6f778d97..922869b3c0 100644 --- a/cypress/support/commands.tsx +++ b/cypress/support/commands.tsx @@ -71,7 +71,7 @@ Cypress.Commands.add('mountWithStoreAndRouter', (component, routes, initialRoute const router = createBrowserRouter(createRoutesFromElements(<> {routes?.length ? routes.map(route => ) - : + : } )); From 653d0d183cbf2c9e583c2892ad33cff8e4b2ba36 Mon Sep 17 00:00:00 2001 From: Jaycie Brown Date: Thu, 3 Sep 2026 16:21:17 +0100 Subject: [PATCH 3/5] Require defined `cy.window()` before mounting router --- cypress/support/commands.tsx | 43 +++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/cypress/support/commands.tsx b/cypress/support/commands.tsx index 922869b3c0..22c2324a01 100644 --- a/cypress/support/commands.tsx +++ b/cypress/support/commands.tsx @@ -63,30 +63,33 @@ import {store} from "../../src/app/state"; import {createBrowserRouter, createRoutesFromElements, Route, To} from "react-router"; import { RouterProvider } from 'react-router-dom'; import { ACTION_TYPE } from '../../src/app/services'; -import {v4 as uuid_v4} from "uuid"; Cypress.Commands.add('mountWithStoreAndRouter', (component, routes, initialRoute=routes?.[0], user, mountOptions) => { - const uuid = uuid_v4(); - - const router = createBrowserRouter(createRoutesFromElements(<> - {routes?.length - ? routes.map(route => ) - : + cy.window().then(window => { + // createBrowserRouter errors with `TypeError: Cannot read properties of null (reading 'history')` if the global window is not defined. + // this seems to happen randomly with certain test setups (MyGameboards.cy.tsx has faced this a lot), but the exact reason remains unknown. + // my best guess is something regarding having two tests that mountWithStoreAndRouter the same component? + + const router = createBrowserRouter(createRoutesFromElements(<> + {routes?.length + ? routes.map(route => ) + : + } + ), { window }); + + if (user) { + void store.dispatch({type: ACTION_TYPE.CURRENT_USER_RESPONSE_SUCCESS, user}); } - )); - - if (user) { - void store.dispatch({type: ACTION_TYPE.CURRENT_USER_RESPONSE_SUCCESS, user}); - } - void router.navigate(initialRoute || '/'); - - mount( - - - , - mountOptions - ); + void router.navigate(initialRoute || '/'); + + mount( + + + , + mountOptions + ); + }); }); import "@frsource/cypress-plugin-visual-regression-diff/dist/support"; From 9a7ec6271586f04ac6059e7ff3d69e6e61171bc6 Mon Sep 17 00:00:00 2001 From: Jaycie Brown Date: Thu, 3 Sep 2026 16:35:25 +0100 Subject: [PATCH 4/5] Restore rerender key idea, but pass into `mount` directly --- cypress/support/commands.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cypress/support/commands.tsx b/cypress/support/commands.tsx index 22c2324a01..3af5091cbb 100644 --- a/cypress/support/commands.tsx +++ b/cypress/support/commands.tsx @@ -63,12 +63,14 @@ import {store} from "../../src/app/state"; import {createBrowserRouter, createRoutesFromElements, Route, To} from "react-router"; import { RouterProvider } from 'react-router-dom'; import { ACTION_TYPE } from '../../src/app/services'; +import { v4 as uuid_v4 } from 'uuid'; Cypress.Commands.add('mountWithStoreAndRouter', (component, routes, initialRoute=routes?.[0], user, mountOptions) => { cy.window().then(window => { // createBrowserRouter errors with `TypeError: Cannot read properties of null (reading 'history')` if the global window is not defined. // this seems to happen randomly with certain test setups (MyGameboards.cy.tsx has faced this a lot), but the exact reason remains unknown. // my best guess is something regarding having two tests that mountWithStoreAndRouter the same component? + const uuid = uuid_v4(); const router = createBrowserRouter(createRoutesFromElements(<> {routes?.length @@ -87,7 +89,8 @@ Cypress.Commands.add('mountWithStoreAndRouter', (component, routes, initialRoute , - mountOptions + mountOptions, + uuid ); }); }); From d422b7b917e5796eabe9064e93dca42baaacbdd2 Mon Sep 17 00:00:00 2001 From: Jaycie Brown Date: Thu, 3 Sep 2026 17:11:14 +0100 Subject: [PATCH 5/5] Update and correct comment --- cypress/support/commands.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cypress/support/commands.tsx b/cypress/support/commands.tsx index 3af5091cbb..aaacd9f189 100644 --- a/cypress/support/commands.tsx +++ b/cypress/support/commands.tsx @@ -68,8 +68,11 @@ import { v4 as uuid_v4 } from 'uuid'; Cypress.Commands.add('mountWithStoreAndRouter', (component, routes, initialRoute=routes?.[0], user, mountOptions) => { cy.window().then(window => { // createBrowserRouter errors with `TypeError: Cannot read properties of null (reading 'history')` if the global window is not defined. - // this seems to happen randomly with certain test setups (MyGameboards.cy.tsx has faced this a lot), but the exact reason remains unknown. - // my best guess is something regarding having two tests that mountWithStoreAndRouter the same component? + // this seems to fatally affect test setups where the "same" component is mounted across multiple tests (c.f. MyGameboards.cy.tsx), + // presumably because there is some state that is not correctly flushed across the tests' teardown/setup. + // + // wrapping the router creation in a `cy.window().then` seems to fix the issue issue with the global window not being defined; + // passing a rerender key to the mount function fixes the issue with stale mounted components being used across tests. const uuid = uuid_v4(); const router = createBrowserRouter(createRoutesFromElements(<>