Coder Social home page Coder Social logo

Comments (29)

pdanpdan avatar pdanpdan commented on September 25, 2024

Hello.
Can you please take a look at #110?
It's about this issue and #67

It's not polished and there are decisions to be made about:

But at least it works with props, events, and slots

from vike-vue.

brillout avatar brillout commented on September 25, 2024
  • should the component be removed

Does <ClientOnly> support any use case that clientOnly() doesn't? If not then, yes, I think we should remove it and release a breaking change and bump the minor semver. We're still on 0.x.y so I think it's ok.

  • the name of the function (maybe createClientOnlyComponent)

I think clientOnly() is both succint and clear?

  • where it is exposed

So far, we export utils at vike-vue/utilName. So vike-vue/clientOnly.

Eventually merging exports to the root export vike-vue is a consideration, but we need to double check whether Rollup's code-splitting works (it should in principle, but we should be sure about it as bloating the client-side is a no-go).

  • the name of the fallback slot (maybe ssr-content)

How about <template #fallback>?

I'll have a look at it later today.

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024
  • I cannot think of anything that <ClientOnly> can do better that the function
  • clientOnly does not convey that it creates a component (defineComponent, defineAsyncComponent - maybe defineClientOnlyComponent)
  • <template #fallback> - I was thinking about avoiding as much as possible to override a named slot of the wrapped component

from vike-vue.

brillout avatar brillout commented on September 25, 2024
  • clientOnly does not convey that it creates a componen

Unless I'm missing some Vue convention, I think it's ok.

  • <template #fallback> - I was thinking about avoiding as much as possible to override a named slot of the wrapped component

Good point. How about an option? For example:

function clientOnly(
  componentLoader: () => Component,
  { fallbackSlotName = 'fallback' }: { fallbackSlotName?: string } = {}
) {
  // ...
}

from vike-vue.

brillout avatar brillout commented on September 25, 2024

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 T extends { new (): ComponentPublicInstance } instead of T extends Component = { new (): ComponentPublicInstance }?

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024

Honestly I was just trying to find a way to pass the type of the imported component to the result of clientOnly.

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024
  • if we allow changing the fallback slot name with parameter we lose the autocomplete
  • I tested with using a Symbol for slot name - it works but autocomplete is not available and one need to import the symbol, so not very nice to use
  • I went the route of using a descriptive name of 'client-only-fallback'

About typing, I cannot make heads or tails of why it accepts something like () => 2, so if someone can bring some sanity there while still keeping autocomplete on use please help.

from vike-vue.

brillout avatar brillout commented on September 25, 2024

@4350pChris WDYT? I'll have a look at it if Chris is busy.

from vike-vue.

brillout avatar brillout commented on September 25, 2024

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 slotName1 and slotName2 in this playground.

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024

I cannot make it work, sorry

from vike-vue.

brillout avatar brillout commented on September 25, 2024
  • if we allow changing the fallback slot name with parameter we lose the autocomplete

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 #client-only-fall VSCode isn't suggesting #client-only-fallback:

image

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024

For me the steps are:

  • pnpm reset
  • reload VSCode so that TS is loaded with new vike-vue
  • it should work now
    I'm almost sure there is some method to force reload TS, but Developer: Reload Window works for sure

from vike-vue.

brillout avatar brillout commented on September 25, 2024

Ah, it works now! Thanks. Sorry I'm a VSCode newbie 😅

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024

No problem - I feel the same with TS magic (especially when combined with Vue)

from vike-vue.

brillout avatar brillout commented on September 25, 2024

Indeed, there doesn't seem to be any Slot type that supports a extends string generic.

Would it be possible to have clientOnly() use #fallback by default and if there is a conflict with the inner component then clientOnly() uses #client-only-fallback instead? Maybe it's a bit tricky to implement?

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024

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)

from vike-vue.

brillout avatar brillout commented on September 25, 2024

It isn't dynamic and instead we define two static slots fallback and client-only-fallback.

from vike-vue.

brillout avatar brillout commented on September 25, 2024

Maybe it's a bit tricky to implement?

If it's too tricky then I'd say let's go for only one slot client-only-fallback. But maybe it's worth trying? I think the docs can be clear:

Use #client-only-fallback if the inner component uses #fallabck.

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024

Ah, you mean like that (define both slots) - it might work. Meanwhile if someone can understand why () => 1 satisfies T extends Component it would help :D

from vike-vue.

brillout avatar brillout commented on September 25, 2024

Looking at it as we speak :)

I think the issue is somewhere else: https://play.vuejs.org/#eNp9kE9PwzAMxb+Klcs2aRpCcJoGEqBJwAEQcMylytzSkTpR4oyiqt8dp9X+HIBb/H4v9rM7deP9YpdQLdUqmlB7hoicPNiCqiutOGp1raluvAsMHQQsDNc7nAN/e4Q7J4CQGHoog2tgIr0mmjSVicToCEqamuXROOt6gTQ9n2lanY0jZYAUjI23BaNU92ity/xEU3MJYxyVdbXYRkeSuNMEoJWR3rXF8OzzQAm8hIFkVkijr8dB45BwvtfNB5rPX/RtbLOm1UvAiGGHWh0YF6FCHvH67QlbeR9g4zbJivsf+IrR2ZQzjrbbRBuJfeIb0j4Mt66peo/rlpHifqkcNDv7wa+VnDqf9a/Vj3EvFpfDP0296n8AX0unrg==

Let me have a closer look.

from vike-vue.

brillout avatar brillout commented on September 25, 2024

Btw. I think you can remove = { new (): ComponentPublicInstance }, since source is a required parameter.

from vike-vue.

brillout avatar brillout commented on September 25, 2024

Actually, () => 1 is a valid Component: https://play.vuejs.org/#eNp9kE9PwzAMxb+Klcs2aRpCcJq2SYAmAQdAwDGXKnNLR+pEiTOGqn53nFb7cwBu8fu92M9u1Y33s11CNVeLaELtGSJy8mALqpZacdRqpaluvAsMLQQsDNc7nAJ/e4Q7J4CQGDoog2tgJL1GmjSVicToCEoam/nJOGk7gTQeT2C5gsuJpsXFMFjGSMHYeFswSnWP1rrMzzQ1lUjGUVlXs210JLlbTQBaGZlQWwzPPo+V2HPoSWaFNPp67DUOCacH3Xyg+fxF38Z91rR6CRgx7FCrI+MiVMgDXr894V7eR9i4TbLi/ge+YnQ25YyD7TbRRmKf+fq0D/3Fa6re43rPSPGwVA6anV3v10oOno/71+qnuFez6/6fpk51P/UzqLo=

Which makes sense from a JSX perspective.

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024

Btw. I think you can remove = { new (): ComponentPublicInstance }, since source is a required parameter.

For some reason if I remove that we lose autocomplete for props/events/slots for resulting component

Actually, () => 1 is a valid Component

Nice - you're right

from vike-vue.

brillout avatar brillout commented on September 25, 2024

For some reason if I remove that we lose autocomplete for props/events/slots for resulting component

Sounds like a Volar quirk.

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024

Yep, editor quirk.
I updated the PR - it has 2 commits - the second one should be removed before merge

from vike-vue.

4350pChris avatar 4350pChris commented on September 25, 2024

@pdanpdan Can I merge this? Looks good from my point of view.

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024

Yes, all done from my point of view

from vike-vue.

pdanpdan avatar pdanpdan commented on September 25, 2024

BTW, do you have any idea about this?
#110 (comment)

from vike-vue.

4350pChris avatar 4350pChris commented on September 25, 2024

BTW, do you have any idea about this?
#110 (comment)

Unfortunately no. I tried a bit and couldn't get it working either.

from vike-vue.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.