Skip to content

Commit

Permalink
Avoid async/await syntax for getMarkupFromTree process function.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Jul 21, 2020
1 parent 950dce2 commit 666fbf3
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/react/ssr/getDataFromTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,26 @@ export function getMarkupFromTree({
}: GetMarkupFromTreeOptions): Promise<string> {
const renderPromises = new RenderPromises();

async function process(): Promise<string> {
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 = await renderFunction(
React.createElement(
ApolloContext.Provider,
{ value: { ...context, renderPromises } },
tree
)
);

return renderPromises.hasPromises()
? renderPromises.consumeAndAwaitPromises().then(process)
: html;
return new Promise<string>(resolve => {
const element = React.createElement(
ApolloContext.Provider,
{ value: { ...context, renderPromises }},
tree,
);
resolve(renderFunction(element));
}).then(html => {
return renderPromises.hasPromises()
? renderPromises.consumeAndAwaitPromises().then(process)
: html;
});
}

return Promise.resolve().then(process);
Expand Down

0 comments on commit 666fbf3

Please sign in to comment.