Skip to content
Myr

fix(jsx): await all promises at once to avoid race condition (#3274)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Taku Amano · committed by GitHub · parent 986db29 · Browse files · 2 files+37 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+37 added−3 removed

  • tests:+33 added−0 removed
  • other:+4 added−3 removed

2 files+37 added−3 removed

modified:src/jsx/index.test.tsx+33 added
110 unmodified lines
111 expect(res.status).toBe(200)112 expect(res.headers.get('Content-Type')).toBe('text/html; charset=UTF-8')113 expect(await res.text()).toBe('<html><body><h1>Hello from async component</h1></body></html>')114 })115116 it('Should handle async component error', async () => {117 const componentError = new Error('Error from async error component')118119 const AsyncComponent = async () => {120 await new Promise((resolve) => setTimeout(resolve, 10))121 return <h1>Hello from async component</h1>122 }123 const AsyncErrorComponent = async () => {124 await new Promise((resolve) => setTimeout(resolve, 0))125 throw componentError126 }127128 let raisedError: any129 app.onError((e, c) => {130 raisedError = e131 return c.html('<html><body><h1>Error from onError</h1></body></html>', 500)132 })133 app.get('/', (c) => {134 return c.html(135 <>136 <AsyncComponent />137 <AsyncErrorComponent />138 </>139 )140 })141142 const res = await app.request('http://localhost/')143 expect(res.status).toBe(500)144 expect(res.headers.get('Content-Type')).toBe('text/html; charset=UTF-8')145 expect(await res.text()).toBe('<html><body><h1>Error from onError</h1></body></html>')146 expect(raisedError).toBe(componentError)147 })148})149150describe('render to string', () => {151 it('Nested array', () => {
900 unmodified lines
modified:src/utils/html.ts+4 added-3 removed