perf: only patch string style when value has changed (#1310)

fix #1309
This commit is contained in:
underfin
2020-06-12 05:25:39 +08:00
committed by GitHub
parent 1f2926a33c
commit d4e9b19932
2 changed files with 19 additions and 1 deletions

View File

@@ -7,6 +7,22 @@ describe(`runtime-dom: style patching`, () => {
expect(el.style.cssText.replace(/\s/g, '')).toBe('color:red;')
})
// #1309
it('should not patch same string style', () => {
const el = document.createElement('div')
const fn = jest.fn()
const value = (el.style.cssText = 'color:red;')
Object.defineProperty(el.style, 'cssText', {
get(): any {
return value
},
set: fn
})
patchProp(el, 'style', value, value)
expect(el.style.cssText.replace(/\s/g, '')).toBe('color:red;')
expect(fn).not.toBeCalled()
})
it('plain object', () => {
const el = document.createElement('div')
patchProp(el, 'style', {}, { color: 'red' })