diff --git a/packages/async-ssr-manager/src/index.ts b/packages/async-ssr-manager/src/index.ts index 5d510c7e4..497cd2b9b 100644 --- a/packages/async-ssr-manager/src/index.ts +++ b/packages/async-ssr-manager/src/index.ts @@ -37,7 +37,7 @@ export interface AsyncSsrManagerV1 { * * @param render A render function that is called for each render pass. */ - renderUntilCompleted(render: () => string): Promise; + renderUntilCompleted(render: () => Promise | string): Promise; /** * This method is intended for consumers, i.e. Feature Apps and Feature diff --git a/packages/async-ssr-manager/src/internal/async-ssr-manager.ts b/packages/async-ssr-manager/src/internal/async-ssr-manager.ts index 852de700a..ccf82c825 100644 --- a/packages/async-ssr-manager/src/internal/async-ssr-manager.ts +++ b/packages/async-ssr-manager/src/internal/async-ssr-manager.ts @@ -16,7 +16,9 @@ export class AsyncSsrManager implements AsyncSsrManagerV1 { private readonly timeout?: number ) {} - public async renderUntilCompleted(render: () => string): Promise { + public async renderUntilCompleted( + render: () => Promise | string + ): Promise { const renderPromise = this.renderingLoop(render); if (typeof this.timeout !== 'number') { @@ -36,8 +38,10 @@ export class AsyncSsrManager implements AsyncSsrManagerV1 { this.asyncOperations.add(asyncOperation); } - private async renderingLoop(render: () => string): Promise { - let html = render(); + private async renderingLoop( + render: () => Promise | string + ): Promise { + let html = await render(); while (this.asyncOperations.size > 0) { while (this.asyncOperations.size > 0) { @@ -54,7 +58,7 @@ export class AsyncSsrManager implements AsyncSsrManagerV1 { await Promise.all(asyncOperationsSnapshot); } - html = render(); + html = await render(); } return html;