Patched elements keep inline styles from old vnodes
See original GitHub issueVue.js version
2.0.6+
Reproduction Link
https://jsfiddle.net/gw8g8cos/
Steps to reproduce
$ vue init webpack-simple .
$ npm install vue@2.0.7 vue-template-compiler@2.0.7
<template>
<div>
<section style="text-align: center" v-if="loading">
Should be centered.
</section>
<section style="margin-top: 6rem;" v-if="!loading">
Should not be centered.
</section>
</div>
</template>
<script>
export default {
name: 'app',
data () {
return {
loading: true
}
},
mounted: function() {
setTimeout(() => {
this.loading = false;
}, 2000);
}
}
</script>
What is Expected?
Patched elements should not keep inline styles from old vnodes.
What is actually happening?
During the update operation, patched elements will retain styles from vnodes that will no longer exist in the DOM.
Temporarily solution for end-users: changing inline styles to classes, choosing different tag names or adding a key
directive will fix the issue. Thanks to @LinusBorg for the latter.
It looks like this PR has introduced this regression https://github.com/vuejs/vue/pull/4138. I’ve opened a pull request with a failing test that confirms this issue.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Inline styles causing problems when replacing an element
I managed to resolve this issue by using a string slice on the HTML element and patching the CSS elements to it. First...
Read more >snabbdom-ng - npm
Any old vnode passed must be the resulting vnode from a previous call to patch or read . This is necessary since Snabbdom...
Read more >Built-in Directives - Vue.js
v-show works by setting the display CSS property via inline styles, and will try to respect the initial display value when the element...
Read more >6. Element Node Inline Styles - DOM Enlightenment [Book]
In the following code, I am accessing the style attribute of a <div> that contains several inline CSS properties. Live code <!DOCTYPE html>...
Read more >maquette - UNPKG
You should normally call the `scheduleRender()` function to keep the\n * user ... n */\n append(parentNode: Element, renderFunction: () => VNode): void;\n ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://github.com/vuejs/vue/blob/dev/src/platforms/web/runtime/modules/style.js#L48
The style now only holds the style binding, which will be removed in the next render. The static style and style binding should be removed both when reusing the same node.
I’ll make a PR to fix it