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

Suspense and async Component Support #50

Open
shellscape opened this issue Nov 8, 2023 · 4 comments
Open

Suspense and async Component Support #50

shellscape opened this issue Nov 8, 2023 · 4 comments
Labels
question Further information is requested

Comments

@shellscape
Copy link

Hey thanks for the package! Any chance of getting Suspense and async support? For reference, hono just added experimental support for that concept https://github.com/honojs/hono/blob/next/src/jsx/streaming.ts#L25

@i-like-robots i-like-robots added the question Further information is requested label Nov 9, 2023
@i-like-robots
Copy link
Owner

i-like-robots commented Nov 9, 2023

Thanks for your question @shellscape.

I have considered implementing a streaming - async - renderer before because JSX is so slow compared to string based template libraries like Handlebars. However, I've not had a reason to invest effort into this.

Because this library doesn't handle state I think any <Suspense> implementation would be very basic - either always rendering the fallback or always waiting for its children to resolve. It's certainly possible to support this to avoid erroring if nothing else.

@shellscape
Copy link
Author

@i-like-robots we're currently using a mishmashed jsx renderer, with a significant portion based on hyperons. we've integrated Suspense support here: https://github.com/shellscape/jsx-email/blob/afd9ca80fe1111e17796901f7bd6c0187c0a0de5/packages/jsx-email/src/render/jsx-to-string.ts#L93-L143

It works well with all of our testing and userland use. Hopefully that's helpful for hyperons.

@i-like-robots
Copy link
Owner

Thank you @shellscape that's very interesting. And I'm really pleased to hear the code has been useful for more people 👍

@i-like-robots
Copy link
Owner

I've added a very basic shim for the <Suspense> component in #51

Longer term, I think supporting async components could be really interesting - not many templating languages do this well but it feels like it could be a fairly natural fit for JSX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants