-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
clientOnly()
function instead of <ClientOnly>
wrapper component
#82
Comments
Hello. It's not polished and there are decisions to be made about:
But at least it works with props, events, and slots |
Does
I think
So far, we export utils at Eventually merging exports to the root export
How about
I'll have a look at it later today. |
|
Unless I'm missing some Vue convention, I think it's ok.
Good point. How about an option? For example: function clientOnly(
componentLoader: () => Component,
{ fallbackSlotName = 'fallback' }: { fallbackSlotName?: string } = {}
) {
// ...
} |
The generic can be any type, maybe we should make it more restrictive? For example, TS won't complain with the following: clientOnly(
() => 12
) Did you mean more something like |
Honestly I was just trying to find a way to pass the type of the imported component to the result of clientOnly. |
About typing, I cannot make heads or tails of why it accepts something like |
@4350pChris WDYT? I'll have a look at it if Chris is busy. |
I don't know much about Volar, but I presume using a generic to do the trick? function clientOnly<Component, FallbackSlotName extends string = 'fallback'>(
componentLoader: () => Component,
{ fallbackSlotName }: { fallbackSlotName?: FallbackSlotName } = {}
) {
// ...
} See for example the type of |
I cannot make it work, sorry |
I can't make autocomplete work at all on my setup. I'm trying with VSCode + Vue plugin, am I missing something? When my cursor hovers |
For me the steps are:
|
Ah, it works now! Thanks. Sorry I'm a VSCode newbie 😅 |
No problem - I feel the same with TS magic (especially when combined with Vue) |
Indeed, there doesn't seem to be any Slot type that supports a Would it be possible to have |
It would be the same problem with TS - we cannot make the slot name dynamic and still expose it in typescript (at least I don;t know how) |
It isn't dynamic and instead we define two static slots |
If it's too tricky then I'd say let's go for only one slot
|
Ah, you mean like that (define both slots) - it might work. Meanwhile if someone can understand why |
Looking at it as we speak :) Let me have a closer look. |
Btw. I think you can remove |
Which makes sense from a JSX perspective. |
For some reason if I remove that we lose autocomplete for props/events/slots for resulting component
Nice - you're right |
Sounds like a Volar quirk. |
Yep, editor quirk. |
@pdanpdan Can I merge this? Looks good from my point of view. |
Yes, all done from my point of view |
BTW, do you have any idea about this? |
Unfortunately no. I tried a bit and couldn't get it working either. |
* feat: replace `ClientOnly` component with `clientOnly` function with TS support #67, #82 BREAKING CHANGE: `ClientOnly` component is removed, please use the new `clientOnly` function to create components that only load and render on client side * chore: some tests to be removed before merge * minor * simplify slots handling? * always require argument to be a function returning a promise? * fix: call alternate fallback slot function * refactor slots definition * swallow error when loading component and expose it as prop for fallback slot * fix slots typing * cleanup examples * expose attrs to fallback slots so styles can be applied if required * minor refactor * let's change the docs URL after vike-react also makes the migration to a clientOnly() function * small tweak of example - move timer to the slow loading component example * more `clientOnly` under helpers --------- Co-authored-by: Romuald Brillout <[email protected]>
See:
I think we can & should also deprecate the
<ClientOnly>
wrapper component in favor of aclientOnly()
function. It's a much nicer DX.The text was updated successfully, but these errors were encountered: