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

Support async components #14

Open
loreanvictor opened this issue Jul 14, 2023 · 0 comments
Open

Support async components #14

loreanvictor opened this issue Jul 14, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@loreanvictor
Copy link
Owner

loreanvictor commented Jul 14, 2023

Add support for async components. This doesn't make much sense in pure client components and results in janky interactions (the component pops into existence after the async task), but

  • Components can be purely server-side, which this is pretty essential,
  • Minicomp isn't the kind of library to decide on UX of stuff built with it.

Async Rendering

So what should be possible is something like this:

define('my-comp', async ({ key }) => {
  const result = await query(key)

  return html`<div>${result.name}</div>`
})

If the component function returns a promise, then the content should be added to the host when that promise is resolved.

Async Rehydration

I don't know whether this would be useful or not. But similarly we could just rehydrate when the promise is resolved (basically, an SSRTemplate is resolved).

Async Generators

This could enable convenient loading states:

define('my-comp', async function* ({ key }) {
  yield html`<div>Loading ...</div>`
  const result = await query(key)
  
  return html`<div>${result.name}</div>`
})

In this case, the previously yielded content will be replaced. For SSRTemplates, each yielded template can try to rehydrate the host, the end result being up to developers to manage (I guess? using such components on server and the client should be considered a bit more).

Hooks

Use of hooks should be before any await keyword, as otherwise the hooks context won't work. This might cause development confusion, so perhaps this requires further contemplation in design? Maybe other mechanisms specifically targeting async server-side rendering (perhaps beyond the scope of this package) are to be used?


@loreanvictor loreanvictor added the enhancement New feature or request label Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant