Skip to content

Remove old static style when applying style update (fix #4227) #4235

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

Merged
merged 4 commits into from
Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/platforms/web/runtime/modules/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ function updateStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) {

let cur, name
const el: any = vnode.elm
const oldStyle: any = oldVnode.data.style || {}
const oldStaticStyle: any = oldVnode.data.staticStyle
const oldStyleBinding: any = oldVnode.data.style || {}

// if static style exists, stylebinding already merged into it when doing normalizeStyleData
const oldStyle = oldStaticStyle || oldStyleBinding

const style = normalizeStyleBinding(vnode.data.style) || {}

vnode.data.style = style.__ob__ ? extend({}, style) : style
Expand Down
23 changes: 16 additions & 7 deletions test/unit/features/directives/style.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,28 @@ describe('Directive v-bind:style', () => {

it('should not merge for different adjacent elements', (done) => {
const vm = new Vue({
template: '<div>' +
'<section style="color: blue" v-if="!bool"></section>' +
'<div></div>' +
'<section style="margin: 0" v-if="bool"></section>' +
'</div>',
template:
'<div>' +
'<section style="color: blue" :style="style" v-if="!bool"></section>' +
'<div></div>' +
'<section style="margin-top: 12px" v-if="bool"></section>' +
'</div>',
data: {
bool: false
bool: false,
style: {
fontSize: '12px'
}
}
}).$mount()
const style = vm.$el.children[0].style
expect(style.fontSize).toBe('12px')
expect(style.color).toBe('blue')
waitForUpdate(() => {
vm.bool = true
}).then(() => {
expect(vm.$el.children[1].style.color).not.toBe('blue')
expect(style.color).toBe('')
expect(style.fontSize).toBe('')
expect(style.marginTop).toBe('12px')
}).then(done)
})
})