Skip to content

Commit 6178ec5

Browse files
mjhenkesmschile
authored andcommitted
chore: [Multi-domain] Clean up stability code. (#20656)
* chore: [Multi-domain] Fix Flake when subdomain loads faster than toSpecBridge Command called. * Add Test * simplify test * Loading a cross domain page won't happen until the spec bridge is active (or a timeout will happen) * Update packages/driver/src/multi-domain/domain_fn.ts
1 parent c33b44c commit 6178ec5

File tree

4 files changed

+4
-19
lines changed

4 files changed

+4
-19
lines changed

packages/driver/src/cy/multi-domain/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy,
173173
hookId: state('hookId'),
174174
hasVisitedAboutBlank: state('hasVisitedAboutBlank'),
175175
multiDomainBaseUrl: location.origin,
176+
isStable: state('isStable'),
176177
},
177178
config: preprocessConfig(Cypress.config()),
178179
env: preprocessEnv(Cypress.env()),
179-
isStable: state('isStable'),
180180
})
181181
} catch (err: any) {
182182
const wrappedErr = $errUtils.errByPath('switchToDomain.run_domain_fn_errored', {

packages/driver/src/multi-domain/cypress.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ const onBeforeAppWindowLoad = (Cypress: Cypress.Cypress, cy: $Cy) => (autWindow:
9898
cy.overrides.wrapNativeMethods(autWindow)
9999

100100
const onWindowLoadPrimary = ({ url }) => {
101-
// If the primary domain has indicated a load event, set stability to undefined, not true since the load happened in another domain.
102-
cy.isStable(undefined, 'primary onload')
101+
cy.isStable(true, 'primary onload')
103102
Cypress.emit('internal:window:load', { type: 'cross:domain', url })
104103
}
105104

packages/driver/src/multi-domain/domain_fn.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const handleDomainFn = (Cypress: Cypress.Cypress, cy: $Cy) => {
8282
}
8383

8484
Cypress.specBridgeCommunicator.on('run:domain:fn', async (options: RunDomainFnOptions) => {
85-
const { config, data, env, fn, state, skipConfigValidation, isStable } = options
85+
const { config, data, env, fn, state, skipConfigValidation } = options
8686

8787
let queueFinished = false
8888

@@ -109,18 +109,6 @@ export const handleDomainFn = (Cypress: Cypress.Cypress, cy: $Cy) => {
109109
Cypress.specBridgeCommunicator.toPrimary('queue:finished', { err }, { syncGlobals: true })
110110
})
111111

112-
// We specifically don't call 'cy.isStable' here because we don't want to inject another load event.
113-
// If stability is true in this domain, that means this domain has loaded itself, in that case trust the domain and run the next command.
114-
if (cy.state('isStable') !== true) {
115-
if (isStable) {
116-
// If stability is established in a different domain, set this domain to undefined
117-
cy.state('isStable', undefined)
118-
} else {
119-
// If the calling domain is unstable set this domain to also be unstable. It indicates that a load even occurred prior to running this domain.
120-
cy.state('isStable', isStable)
121-
}
122-
}
123-
124112
try {
125113
const value = window.eval(`(${fn})`)(data)
126114

packages/runner-shared/src/event-manager.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,7 @@ export const eventManager = {
532532
// Only listen to window load events from the most recent secondary domain, This prevents nondeterminism in the case where we redirect to an already
533533
// established spec bridge, but one that is not the current or next switchToDomain command.
534534
if (cy.state('latestActiveDomain') === domain) {
535-
// Since stability was established in another domain set stable to undefined, not true. Undefined and true are treated the same stability.ts, but
536-
// it allows us to distinguish between a load event that ocurred in this domain and some that didn't (or the initial state)
537-
cy.isStable(undefined, 'load')
535+
cy.isStable(true, 'load')
538536
// Prints out the newly loaded URL
539537
Cypress.emit('internal:window:load', { type: 'cross:domain', url })
540538
}

0 commit comments

Comments
 (0)