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: Revert DOM clean up methods #160

Merged
merged 2 commits into from
Apr 18, 2019
Merged

fix: Revert DOM clean up methods #160

merged 2 commits into from
Apr 18, 2019

Conversation

Robdel12
Copy link
Contributor

@Robdel12 Robdel12 commented Apr 17, 2019

Why?

Given this JSBin: https://jsbin.com/?html,console,output

When we serialize the CSSOM into the <style> tag that the in-memory styles own and then remove those styles, it triggers deleteRule on those styles in the CSSOM. Which means we're removing the text we injected AND all of the styles that live in memory. This breaks their app.

With the input cleaning, when we remove the value or checked attribute on the element, it's possible those elements lose their values entirely. For example, when we remove the checked attribute from checkboxes in the customers DOM, this will make the checkbox no longer checked, which is changing the state of their application. It would be better, in this world without an AST, to leave the mutations in place. Removing the mutations causes more issues than it tries to solve.

Future solve

I think we should really explore transforming their DOM into an AST and modifying it after we've POST'ed it to the agent process. This would 100% ensure we're not mutating the customers DOM in any way. This is not a simple change, but I believe it is the right change.

TODO

  • Fix the tests that fail related to DOM clean up

Given this JSBin: https://jsbin.com/?html,console,output

When we serialize the CSSOM into the `<style>` tag that the in-memory
styles own and then _remove_ those styles, it triggers `deleteRule` on
those styles in the CSSOM. Which means we're removing the text we
injected AND all of the styles that live in memory. This breaks their
app.

With the input cleaning, when we remove the value or
checked attribute on the element, it's possible those elements lose
their values entirely. For example, when we remove the `checked`
attribute from checkboxes in the customers DOM, this will make the
checkbox _no longer checked_, which is changing the state of their
application. It would be better, in this world without an AST, to
leave the mutations in place. Removing the mutations causes more
issues than it tries to solve.
@Robdel12 Robdel12 requested a review from djones April 17, 2019 21:26
Copy link
Contributor

@maprules1000 maprules1000 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Might want to wait on @djones to review too

expect(domSnapshot).to.contain('.box { height: 500px; width: 500px; background-color: green; }')

// we want to ensure mutiple snapshots are successful
const secondDomSnapshot = await snapshot(page, 'Serialize CSSOM twice')
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@djones djones left a comment

Choose a reason for hiding this comment

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

🍍 LGTM

@Robdel12 Robdel12 merged commit 12ab332 into master Apr 18, 2019
@Robdel12 Robdel12 deleted the rd/revert-dom-cleaning branch April 18, 2019 19:49
djones pushed a commit that referenced this pull request Apr 18, 2019
## [0.3.1](v0.3.0...v0.3.1) (2019-04-18)

### Bug Fixes

* Revert DOM clean up methods ([#160](#160)) ([12ab332](12ab332))
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.

3 participants