Warn about reusing mutated attrs object - fixes #2719
This commit is contained in:
parent
8ef7844f5a
commit
b97fd59381
2 changed files with 20 additions and 0 deletions
|
|
@ -800,6 +800,9 @@ module.exports = function($window) {
|
|||
if ("selectedIndex" in attrs) setAttr(vnode, "selectedIndex", null, attrs.selectedIndex, undefined)
|
||||
}
|
||||
function updateAttrs(vnode, old, attrs, ns) {
|
||||
if (old && old === attrs) {
|
||||
console.warn("Don't reuse attrs object, use new object for every redraw, this will throw in next major")
|
||||
}
|
||||
if (attrs != null) {
|
||||
// If you assign an input type that is not supported by IE 11 with an assignment expression, an error will occur.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -756,4 +756,21 @@ o.spec("attributes", function() {
|
|||
o(succeeded).equals(true)
|
||||
})
|
||||
})
|
||||
o.spec("mutate attr object", function() {
|
||||
o("warn when reusing attrs object", function() {
|
||||
const _consoleWarn = console.warn
|
||||
console.warn = o.spy()
|
||||
|
||||
const attrs = {className: "on"}
|
||||
render(root, {tag: "input", attrs})
|
||||
|
||||
attrs.className = "off"
|
||||
render(root, {tag: "input", attrs})
|
||||
|
||||
o(console.warn.callCount).equals(1)
|
||||
o(console.warn.args[0]).equals("Don't reuse attrs object, use new object for every redraw, this will throw in next major")
|
||||
|
||||
console.warn = _consoleWarn
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue