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

Defer loading default slot with scopedSlots #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ export default {
default: 'div'
}
},
render(h, { parent, slots, props }) {
const { default: defaultSlot = [], placeholder: placeholderSlot } = slots()

render(h, { parent, scopedSlots, props }) {
if (parent._isMounted) {
return defaultSlot
return scopedSlots.default(undefined)
}

parent.$once('hook:mounted', () => {
parent.$forceUpdate()
})

const placeholderSlot = scopedSlots.placeholder(undefined) || []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work if there is no placeholder.


if (props.placeholderTag && (props.placeholder || placeholderSlot)) {
return h(
props.placeholderTag,
Expand All @@ -29,6 +29,8 @@ export default {
)
}

const defaultSlot = scopedSlots.default(undefined) || []

// Return a placeholder element for each child in the default slot
// Or if no children return a single placeholder
return defaultSlot.length > 0 ? defaultSlot.map(() => h(false)) : h(false)
Expand Down