parent
1f2926a33c
commit
d4e9b19932
@ -7,6 +7,22 @@ describe(`runtime-dom: style patching`, () => {
|
|||||||
expect(el.style.cssText.replace(/\s/g, '')).toBe('color:red;')
|
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', () => {
|
it('plain object', () => {
|
||||||
const el = document.createElement('div')
|
const el = document.createElement('div')
|
||||||
patchProp(el, 'style', {}, { color: 'red' })
|
patchProp(el, 'style', {}, { color: 'red' })
|
||||||
|
@ -8,7 +8,9 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
|
|||||||
if (!next) {
|
if (!next) {
|
||||||
el.removeAttribute('style')
|
el.removeAttribute('style')
|
||||||
} else if (isString(next)) {
|
} else if (isString(next)) {
|
||||||
style.cssText = next
|
if (prev !== next) {
|
||||||
|
style.cssText = next
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const key in next) {
|
for (const key in next) {
|
||||||
setStyle(style, key, next[key] as string)
|
setStyle(style, key, next[key] as string)
|
||||||
|
Loading…
Reference in New Issue
Block a user