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

fix(@cypress/react): Devtools unpredictable resets #15612

Merged
merged 15 commits into from Mar 25, 2021

Conversation

dmtrKovalenko
Copy link
Contributor

This PR reduces unpredictable resets of the dev tools plugin. The main problem for our UI plugin architecture right now is our react components structure which sometimes recreates the whole subtree (of react-split-pane) and the root element of devtools gets recreated and replaced with a completely new one – so we see it empty.

But somewhere in memory there is still a pointer to the dom element that gets updated via devtools 🤦‍♂️

Devtools will flush also if the bridge is stale, but this happens only if we are not touching nor dev tools nor react app for some period of time, so I don't think this a problem.

@dmtrKovalenko dmtrKovalenko requested a review from a team March 22, 2021 13:22
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 22, 2021

Thanks for taking the time to open a PR!

@cypress
Copy link

cypress bot commented Mar 22, 2021



Test summary

9407 0 119 3Flakiness 1


Run details

Project cypress
Status Passed
Commit 9c611c0
Started Mar 24, 2021 11:18 PM
Ended Mar 24, 2021 11:29 PM
Duration 11:00 💡
OS Linux Debian - 10.5
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

cypress/integration/retries.ui.spec.js Flakiness
1 runner/cypress retries.ui.spec > opens attempt on each attempt failure for the screenshot, and closes after test passes

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@lmiller1990
Copy link
Contributor

I confirmed you can open/close the devtools many times without problem.

I see we will have the bug where it renders a <RunnerCt> for each test. Maybe unrelated to this PR.

image

lmiller1990
lmiller1990 previously approved these changes Mar 23, 2021
Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix seems fine, I found another bug (perhaps existing, perhaps regression) and added a comment.

I'll leave fixing and/or merging up to @dmtrKovalenko. For now ✔️ for the fix.

@dmtrKovalenko
Copy link
Contributor Author

Thanks 🙏 for finding a regression.

@lmiller1990 lmiller1990 self-requested a review March 23, 2021 05:19
Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a regression/potential issue, left a comment.

@dmtrKovalenko
Copy link
Contributor Author

This issue reproducing again in develop
image

@dmtrKovalenko
Copy link
Contributor Author

dmtrKovalenko commented Mar 23, 2021

Hey, @elevatebart I removed a bunch of code from your PR #15275 because it was a reason of duplicated components in devtools. Let me know if I broke something

Copy link
Contributor

@elevatebart elevatebart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a branch where I bring back the non framework specific teardown.
You can either

  • cherry-pick the 2 commits (fa449e4, 48dc6f5)
  • merge the branch into this one (feat/react-devtools-resets-fix)
  • remove the support unit test
  • make the support unit test use mount and do the teardown of the body there...

packages/runner-ct/static/index.html Show resolved Hide resolved
npm/webpack-dev-server/src/aut-runner.ts Outdated Show resolved Hide resolved
npm/webpack-dev-server/src/aut-runner.ts Outdated Show resolved Hide resolved
@lmiller1990
Copy link
Contributor

@dmtrKovalenko Seems that removing some clean up breaks a spec in Vue where it wants to reset the state each test. I am not sure how important this test actually is, though.

Can give it another test when you are happy with it, pls let me know.

elevatebart
elevatebart previously approved these changes Mar 24, 2021
// Before all tests we are mounting the root element, **not beforeEach**
// Cleaning up platform between tests is the responsibility of the specific adapter
// because unmounting react/vue component should be done using specific framework API
// (for devtools and to get rid of global event listeners from previous tests.)
Cypress.on('test:before:run', () => {
document.head.innerHTML = headInnerHTML
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, @elevatebart I appreciate your help, but I still don't understand why this should be a part of webpack-dev-server. It looks like not the job of the dev server at all.

I understand that turning this on requires additional import and we can make a specific entry point for this. Ideally, it should be something like:

// support.js file
import { cleanup } from '@cypress/ct-core'

beforeEach(() => { 
  cleanup()
}) 
// and in @cypress{react/vue} we can do
import { cleanup } from '@cypress/ct-core'

beforeEach(() => {
  framworkSpecificUnmount()
  cleanup()
}

It's something @JessicaSachs was talking about for a long time

If somebody is going to not use our framework – let him clean up his code on his own. It just looks like trying to solve a problem that does not exist.

For reference: the testing library provides auto cleanup just like we do, but if you do can also use it manually I think for tests like this

https://testing-library.com/docs/svelte-testing-library/api/#cleanup

Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working way better now. Great!

@lmiller1990 lmiller1990 merged commit b1f831a into develop Mar 25, 2021
@lmiller1990 lmiller1990 deleted the feat/react-devtools-resets branch March 25, 2021 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants