question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Patched elements keep inline styles from old vnodes

See original GitHub issue

Vue.js version

2.0.6+

Reproduction Link

https://jsfiddle.net/gw8g8cos/

vue-glitch

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:closed
  • Created 7 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
defcccommented, Nov 17, 2016

https://github.com/vuejs/vue/blob/dev/src/platforms/web/runtime/modules/style.js#L48

const style = normalizeStyleBinding(vnode.data.style) || {}
vnode.data.style = style.__ob__ ? extend({}, style) : style
const newStyle = getStyle(vnode, true)

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.

0reactions
defcccommented, Nov 17, 2016

I’ll make a PR to fix it

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found