Skip to content

Commit

Permalink
fix(prerender): flatten hAsync children to resolve promises
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Aug 28, 2020
1 parent 16de872 commit 363d258
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/hydrate/platform/h-async.ts
@@ -1,15 +1,16 @@
import * as d from '../../declarations';
import type * as d from '../../declarations';
import { consoleDevError } from '@platform';
import { h } from '@runtime';
import { isPromise } from '@utils';
import { consoleDevError } from '@platform';

export const hAsync = (nodeName: any, vnodeData: any, ...children: d.ChildType[]) => {
if (Array.isArray(children) && children.length > 0) {
// only return a promise if we have to
if (children.some(isPromise)) {
const flatChildren = children.flat(Infinity);
if (flatChildren.some(isPromise)) {
// has children and at least one of them is async
// wait on all of them to be resolved
return Promise.all(children)
return Promise.all(flatChildren)
.then(resolvedChildren => {
return h(nodeName, vnodeData, ...resolvedChildren);
})
Expand Down

0 comments on commit 363d258

Please sign in to comment.