diff --git a/src/jsx/components.test.tsx b/src/jsx/components.test.tsx index 43696d59..9f64eec1 100644 --- a/src/jsx/components.test.tsx +++ b/src/jsx/components.test.tsx @@ -191,6 +191,34 @@ describe('ErrorBoundary', () => { }) }) + describe('async : setTimeout', async () => { + const TimeoutSuccessComponent = async () => { + await new Promise((resolve) => setTimeout(resolve, 10)) + return
OK
+ } + const TimeoutErrorComponent = async () => { + await new Promise((resolve) => setTimeout(resolve, 0)) + throw new Error('Error') + } + + it('fallback', async () => { + const html = ( + <> + + }> + + + + ).toString() + + expect((await resolveCallback(await html)).toString()).toEqual( + '
OK
Out Of Service
' + ) + + suspenseCounter-- + }) + }) + describe('streaming', async () => { const Component = async ({ error }: { error?: boolean }) => { await new Promise((resolve) => setTimeout(resolve, 10)) diff --git a/src/jsx/components.ts b/src/jsx/components.ts index 846b1fd4..060d67c8 100644 --- a/src/jsx/components.ts +++ b/src/jsx/components.ts @@ -93,13 +93,19 @@ d.replaceWith(c.content) })(document) ` } + + let error: unknown + const promiseAll = Promise.all(resArray).catch((e) => (error = e)) return raw(``, [ ({ phase, buffer, context }) => { if (phase === HtmlEscapedCallbackPhase.BeforeStream) { return } - return Promise.all(resArray) - .then(async (htmlArray) => { + return promiseAll + .then(async (htmlArray: HtmlEscapedString[]) => { + if (error) { + throw error + } htmlArray = htmlArray.flat() const content = htmlArray.join('') let html = buffer