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 useSlots().default method to determine whether the slot is in doubt after the contents of the slot have been commented out #7699

Open
DavidAwing opened this issue Feb 13, 2023 · 5 comments

Comments

@DavidAwing
Copy link

DavidAwing commented Feb 13, 2023

Vue version

^3.2.13

Link to minimal reproduction

https://sfc.vuejs.org/#eNqNUctuwjAQ/JXFl4LaOHdIkar2D8rRlzTZQFD8kHdDK6H8e9d5FC5IlSx5H7PjnfFVvYWgLz2qrSqoim1gIOQ+7I1rbfCRAT47z4fyCE30Fp50/u7tOPJknHFFPk0JXhJGG7qSUTIAKOr2MkaGDRczTQJKOpZWWTaBDqeWQE7p5DjPQlFDaLFC8A1UvsYiTzjIshthfmOUx2BCpI3+tlAvahKR2TLoM3knMq8jwdwgo7YwVlJNRKXcqBNzoG2eU1MlpWfSPh5ziXTsHbcWNZLNvqL/JoxCbFSiGIwb5MnFn8eWXqEnTNsTDLOti5+VdyR46X1gU/YdwyusVgt8vdH1VN7BhPUd6s4f10bNDcCflpiSCni+J9rs/vlbS5xmgZHE6ftWKu+FKF2PnR9+AULVzac=

Steps to reproduce

SlotTag Component:

html:

script: const slotDefault = !!useSlots().default; console.log("default exists: " + slotDefault);

App.vue:
html:


browser console output:
default exists: (...args) => {
// If a user calls a compiled slot inside a template expression (#1745), it
// can mess up block tracking, so by default we disable block tracking and
// force bail out whe…

What is expected?

the code for the annotation should not be detected, expecting a undefined value to be returned
Expect the output to be log below:
default exists: false

What is actually happening?

I'm furiously reading the vue design and implementation book, trying to figure out what's going on

System Info

No response

Any additional comments?

No response

@AlexVagrant
Copy link
Contributor

I think you can find why useSlots().default is a function from this line:https://github.com/vuejs/core/blob/main/packages/runtime-core/src/componentSlots.ts#L130.
I hope that can help you.

@puppet-666
Copy link

I have the same question.

@puppet-666
Copy link

puppet-666 commented Mar 7, 2023

I think you can find why useSlots().default is a function from this line:https://github.com/vuejs/core/blob/main/packages/runtime-core/src/componentSlots.ts#L130. I hope that can help you.

I think the problem is not whether useSlots().default is a function, but whether the comment node can be judged in slot by passing in
my example

@puppet-666
Copy link

image

@DavidAwing
After looking at the compiled result, the comment node is also a case of vnode, so there is no problem with useSlots().default being true. But I still think this performance makes me confused in development ....

@puppet-666
Copy link

fe40053dc9ac651ced88a93145add13

One more question is: since the comment node vnode is created, why is this comment not mounted when viewing dom?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants