Defer loading default slot with scopedSlots #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.