Created
November 13, 2023 06:25
-
-
Save yusukebe/a35e2d53c87cc28729c64e11a7f8386d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Hono } from 'hono' | |
import { jsxRenderer } from 'hono/jsx-renderer' | |
import { Suspense } from 'hono/jsx/streaming' | |
const app = new Hono() | |
const Component = async () => { | |
const res = await fetch('https://ramen-api.dev/shops/yoshimuraya') | |
const data = await res.json<{ shop: { name: string } }>() | |
return <div>{data.shop.name} 🍜</div> | |
} | |
app.get( | |
'*', | |
jsxRenderer( | |
({ children }) => { | |
return ( | |
<html> | |
<body>{children}</body> | |
</html> | |
) | |
}, | |
{ | |
stream: true | |
} | |
) | |
) | |
app.get('/', (c) => { | |
return c.render( | |
<Suspense fallback={<div>loading...</div>}> | |
<Component /> | |
</Suspense> | |
) | |
}) | |
export default app |
How about using Chrome?
Ooh, I just tried Chrome and it works great. It is a safari thing then 😅
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Yusukebe,
I did test this code on my end and suspend is supposed not to block the rendering of other elements but the one within the
suspense
tag right?I've included an example video below. I did delay the fetch by 8 seconds you can check the code example here: https://gist.github.com/cabaalexander/6b74ee956a17d08ae7859d8b1dfa1a7b#file-suspense-tsx-L8
Screen.Recording.2024-02-24.at.2.14.24.AM.mov
Am I missing something or is this right? Thank you.