Skip to content
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

use slotted() in component is not working when use transition element #2892

Closed
pgy108103 opened this issue Dec 27, 2020 · 4 comments · Fixed by #3374
Closed

use slotted() in component is not working when use transition element #2892

pgy108103 opened this issue Dec 27, 2020 · 4 comments · Fixed by #3374
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working scope: slots scope: transition

Comments

@pgy108103
Copy link

Version

3.0.4

Reproduction link

https://github.com/pgy108103/vue3_vite_issue_sample

Steps to reproduce

Change hasTransition flage in todo.vue, you will see that.

What is expected?

I want transition elements to be used with components that use slotted()

What is actually happening?

As title.

@edison1105
Copy link
Member

edison1105 commented Dec 30, 2020

const setScopeId = (
    el: RendererElement,
    scopeId: string | false | null,
    vnode: VNode,
    parentComponent: ComponentInternalInstance | null
  ) => {
    if (scopeId) {
      hostSetScopeId(el, scopeId)
    }
    if (parentComponent) {
      const treeOwnerId = parentComponent.type.__scopeId
      // vnode's own scopeId and the current patched component's scopeId is
      // different - this is a slot content node.
      if (treeOwnerId && treeOwnerId !== scopeId) {
        hostSetScopeId(el, treeOwnerId + '-s')
      }
      //.....
    }
  }

caused by: scopeId is incorrectly set, causing css to not take effect.

if slot's parentComponent is Transition or KeepAlive.parentComponent.type.__scopeId is null,but parentComponent.subTree.scopeId has the correct value.

@HcySunYang
Copy link
Member

@edison1105 Your fix does not solve the real cause. And there are problems according to your changes, let's say if the Transition has an out-in mode, then the subtree may be undefined. I made another PR, see #3150

@edison1105
Copy link
Member

@edison1105 Your fix does not solve the real cause. And there are problems according to your changes, let's say if the Transition has an out-in mode, then the subtree may be undefined. I made another PR, see #3150

Nice to know this and I will close my PR.

@LinusBorg LinusBorg added the ❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. label Feb 4, 2021
@yyx990803
Copy link
Member

yyx990803 commented Mar 2, 2021

Update: the root cause of this is flawed implementation of :slotted scoped id logic. Currently, the following fails:

<Comp>
  <slot/>
</Comp>

<style scoped>
:slotted(*) { color: red }
</style>

#3150 only special cases internal components like Transition, but the ideal behavior is for :slotted to be able to affect elements inside <slot/> regardless of whether it's passed to another component's slot.

I'm working on a fix for this but it requires a pretty substantial refactor and may take a while.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working scope: slots scope: transition
Projects
None yet
5 participants