Skip to content

Commit

Permalink
Support async render function in getDataFromTree / getMarkupFromTree
Browse files Browse the repository at this point in the history
  • Loading branch information
richardscarrott committed Jul 11, 2020
1 parent 190a7f6 commit 80be842
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/react/ssr/getDataFromTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function getDataFromTree(
export type GetMarkupFromTreeOptions = {
tree: React.ReactNode;
context?: { [key: string]: any };
renderFunction?: (tree: React.ReactElement<any>) => string;
renderFunction?: (tree: React.ReactElement<any>) => string | Promise<string>;
};

export function getMarkupFromTree({
Expand All @@ -31,14 +31,14 @@ export function getMarkupFromTree({
}: GetMarkupFromTreeOptions): Promise<string> {
const renderPromises = new RenderPromises();

function process(): Promise<string> | string {
async function process(): Promise<string> {
// 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 } },
Expand Down

0 comments on commit 80be842

Please sign in to comment.