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

Conversation

kedrzu
Copy link

@kedrzu kedrzu commented May 4, 2020

There is a problem when using this in SSR mode. Take this issue as example: #41

Or this question on SO: https://stackoverflow.com/questions/59347414/why-is-my-client-only-component-in-nuxt-complaining-that-window-is-not-define

The problem has its root in the fact, that executing slots() function executes the whole Virtual DOM for the default slot, even if it won't be used afterwards, like in SSR mode.
If you try to use some client-side component inside, even with lazy loading, it will fail, because virtual dom for this component will be executed even on server side.

Cleanest solution is to used scopedSlots, which are lazy loaded, you can run the slot virtual dom function only if you are sure, that it's a client side. Using this is trivial to make client-only, asynchronously loaded components without hacks.

This allows to use client-only also with components that are not well prepared for SSR.

}

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.

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