Skip to content

How do Preact Async Server Components work? #2164

Closed Answered by marvinhagemeister
andreafuturi asked this question in Q&A
Discussion options

You must be logged in to vote

The trick we use to make async routes work is that they are not actual Preact components. Support for async components in preact-render-to-string is still pending. Instead, async routes in Fresh are essentially functions that happen to return JSX nodes. So we call all async functions before rendering, collect the return value and then do a synchronous render with preact-render-to-string.

This has the downside that hooks or other Preact features don't work inside async routes, but given that most folks rather use them to query data from an API or a database, they tend to not need Preact features there.

You might be interested in this PR to preact-render-to-string which is an attempt at asy…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by andreafuturi
Comment options

You must be logged in to vote
2 replies
@marvinhagemeister
Comment options

@andreafuturi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants