Skip to content

Instantly share code, notes, and snippets.

@yusukebe
Created November 13, 2023 06:25
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yusukebe/a35e2d53c87cc28729c64e11a7f8386d to your computer and use it in GitHub Desktop.
Save yusukebe/a35e2d53c87cc28729c64e11a7f8386d to your computer and use it in GitHub Desktop.
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
@cabaalexander
Copy link

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.

@yusukebe
Copy link
Author

How about using Chrome?

@cabaalexander
Copy link

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