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

[WIP] Fix named functional text slots #734

Closed

Conversation

TheAlexLichter
Copy link
Contributor

After #733, default text-slots work quite well. But named slots are awkwardly merged in the default slot variable. I'm working on a fix.

@TheAlexLichter
Copy link
Contributor Author

TheAlexLichter commented Jun 18, 2018

I've looked into template compilation with Vue.compile.

If you want to achieve the same in template mode (without a render function), you'd do:

<template>
  <template slot='hey'>
    Hi
  </template>
<template>

This will be compiled to

with(this){return [_c('template',{slot:"hey"},[_v("Hi")])]}

So we could leverage the _c and _v method to achieve it, but I'm unsure if we should do this 🤔

@eddyerburgh
Copy link
Member

Yes we could use _v, but it would be better if we could construct with h.

@eddyerburgh
Copy link
Member

eddyerburgh commented Jun 18, 2018

We could compile the slot using that template:

compileToFunctions(`<template slot="${name}">${slotValue}</template>`) (https://github.com/vuejs/vue-test-utils/blob/dev/packages/create-instance/add-slots.js#L15)

@TheAlexLichter
Copy link
Contributor Author

TheAlexLichter commented Jun 18, 2018

Nice idea but I've realized that we can use neither template nor slot as root element:

Cannot use template as component root element because it may contain multiple nodes.

I've tried it with text only but this also fails:

Component template requires a root element, rather than just text.

@eddyerburgh
Copy link
Member

Ok, we could render it in a parent div, then use the child vNode when we call h

const node  = compileToFunctions(`<template slot="${name}">${slotValue}</template>`)
h(node).children[0]

@eddyerburgh
Copy link
Member

@manniL did you try the suggested approach ^^

@TheAlexLichter
Copy link
Contributor Author

@eddyerburgh Not yet. Will look into it in the next days!

This was referenced Jul 22, 2018
@eddyerburgh
Copy link
Member

After thinking about this, I don't think we should add this feature.

Since named slots cannot take root text nodes, we shouldn't support them. Instead you can wrap them in a template:

mount(TestComponent, {
  slots: {
    footer: '<template>hey</template>'
  }  
})

@TheAlexLichter TheAlexLichter deleted the fix-named-functional-slots branch July 28, 2018 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants