forked from kitajs/html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.tsx
80 lines (67 loc) · 1.73 KB
/
test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import http from 'http'
import { setTimeout } from 'timers/promises'
import Html from './index'
import { Suspense, renderToStream } from './suspense'
async function WaitFor({ s }: { s: number }) {
await setTimeout(Number(s) * 1000)
return <div>Loaded after: {s}s</div>
}
function render(rid: number) {
return (
<>
<div>Hello</div>
<Suspense rid={rid} fallback={<div>loading 2s</div>}>
<div style="color: red">
<WaitFor s={1} />
</div>
<div style="color: red">
<WaitFor s={1} />
</div>
</Suspense>
<div>World</div>
<Suspense rid={rid} fallback={<div>loading 3s</div>}>
<div style="color: green">
<WaitFor s={3} />
</div>
<div style="color: green">
<WaitFor s={3} />
</div>
</Suspense>
<div>World</div>
<Suspense rid={rid} fallback={<div>loading 2s</div>}>
<div style="color: blue">
<WaitFor s={2} />
</div>
<div style="color: blue">
<WaitFor s={2} />
</div>
</Suspense>
<div>World</div>
<Suspense rid={rid} fallback={<div>loading random</div>}>
<div style="color: green">
<WaitFor s={3} />
</div>
<div style="color: green">
<WaitFor s={4.5} />
</div>
</Suspense>
<div>World</div>
</>
)
}
setInterval(() => {
console.log(SUSPENSE_ROOT)
}, 500)
http
.createServer((req, res) => {
if (req.url === '/') {
res.setHeader('Content-Type', 'text/html; charset=utf-8')
renderToStream(render).pipe(res)
return
}
// Ends the response manually
res.end()
})
.listen(8080, () => {
console.log('http://localhost:8080')
})