Skip to content

Commit

Permalink
Bypass css text (#2811)
Browse files Browse the repository at this point in the history
* [DOM mocks] enable setting element.style

* Use the style setter directly
  • Loading branch information
pygy authored Jan 17, 2023
1 parent 645cf66 commit c1fc1de
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions render/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,10 @@ module.exports = function($window) {
// Styles are equivalent, do nothing.
} else if (style == null) {
// New style is missing, just clear it.
element.style.cssText = ""
element.style = ""
} else if (typeof style !== "object") {
// New style is a string, let engine deal with patching.
element.style.cssText = style
element.style = style
} else if (old == null || typeof old !== "object") {
// `old` is missing or a string, `style` is an object.
element.style.cssText = ""
Expand Down
5 changes: 2 additions & 3 deletions test-utils/domMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,8 @@ module.exports = function(options) {
get style() {
return style
},
set style(_){
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style#Setting_style
throw new Error("setting element.style is not portable")
set style(value){
this.style.cssText = value
},
get className() {
return this.attributes["class"] ? this.attributes["class"].value : ""
Expand Down
13 changes: 5 additions & 8 deletions test-utils/tests/test-domMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,13 @@ o.spec("domMock", function() {
o(div.style.background).equals("url('/*foo*/')")

})
o("setting style throws", function () {
o("setting style updates style.cssText", function () {
var div = $document.createElement("div")
var err = false
try {
div.style = ""
} catch (e) {
err = e
}
div.style = "background: red;"

o(div.style.background).equals("red")
o(div.style.cssText).equals("background: red;")

o(err instanceof Error).equals(true)
})
})
o.spec("events", function() {
Expand Down

0 comments on commit c1fc1de

Please sign in to comment.