Vue: Scoped CSS attribute is reused or discarded when switching between components with scoped CSS

Created on 20 Aug 2019  路  7Comments  路  Source: vuejs/vue

Version

2.6.10

Reproduction link

Steps to reproduce

After npm run serve, click the toggle button and find that child has no style.

Child and child2 components are reused, child's data-v-* disappears, causing the style to disappear

What is expected?

Child should have a black background scope style

What is actually happening?

Child without style

bug contribution welcome

All 7 comments

not only functional components,use functional components just to make sameVnode true,a functional component and a normal dom is ok as well

i add two lines code in patchVnode,and it work will at my demo,but i'm not sure

oldVnode.fnScopeId = vnode.fnScopeId; setScope(oldVnode);

mt44X9.png

I tested with the 4 possible combinations among regular and functional components and the problem only appears when both are functional

If you are up to give the fix a try, you can. If other things break, you should see tests failing

if samaVnode true then patchVnode

mUrTBT.png

regular component's tag will changed,but functional component not

mUrxjx.png

so,a normal dom is ok as well

//parent.vue

<template>
  <div class="parent">
    <Child class="child" v-if="!test"/>
    <div class="child2" v-if="test">
  </div>
</template>

similar bug, affected pure normal components with slot, please see my simple demo.

https://codesandbox.io/s/vue-template-jimot

@CzBiX
I think your problem is same with me.
two child reused but scopedId not be copied .
mRH28I.png

@sin1ght It's weird I couldn't see the problem in your repro using regular components but others' repro do show so I adapted the title. Sorry about that!

Was this page helpful?
0 / 5 - 0 ratings