diff --git a/src/react/ssr/getDataFromTree.ts b/src/react/ssr/getDataFromTree.ts index 8c5972a9eea..e2360bbd0cc 100644 --- a/src/react/ssr/getDataFromTree.ts +++ b/src/react/ssr/getDataFromTree.ts @@ -18,7 +18,7 @@ export function getDataFromTree( export type GetMarkupFromTreeOptions = { tree: React.ReactNode; context?: { [key: string]: any }; - renderFunction?: (tree: React.ReactElement) => string; + renderFunction?: (tree: React.ReactElement) => string | Promise; }; export function getMarkupFromTree({ @@ -31,14 +31,14 @@ export function getMarkupFromTree({ }: GetMarkupFromTreeOptions): Promise { const renderPromises = new RenderPromises(); - function process(): Promise | string { + async function process(): Promise { // Always re-render from the rootElement, even though it might seem // better to render the children of the component responsible for the // promise, because it is not possible to reconstruct the full context // of the original rendering (including all unknown context provider // elements) for a subtree of the original component tree. const ApolloContext = getApolloContext(); - const html = renderFunction( + const html = await renderFunction( React.createElement( ApolloContext.Provider, { value: { ...context, renderPromises } },