vue icon indicating copy to clipboard operation
vue copied to clipboard

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

Open sin1ght opened this issue 5 years ago • 9 comments

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

sin1ght avatar Aug 20 '19 16:08 sin1ght

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

sin1ght avatar Aug 20 '19 21:08 sin1ght

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

sin1ght avatar Aug 21 '19 03:08 sin1ght

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

posva avatar Aug 21 '19 10:08 posva

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>

sin1ght avatar Aug 21 '19 11:08 sin1ght

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

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

CzBiX avatar Aug 25 '19 15:08 CzBiX

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

sin1ght avatar Aug 26 '19 02:08 sin1ght

@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!

posva avatar Aug 29 '19 11:08 posva

Hi, I'm interested interested in this particular task, how to I go ahead

Eceegit avatar Dec 17 '22 05:12 Eceegit

@posva I submitted a pull request for this issue #12938 . But I noticed the requirements state that I should merge to main instead of dev, even though the Contributing Guide says I shouldn't.

Should I make one for main instead?

NoahKa0 avatar Jan 18 '23 21:01 NoahKa0