-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(prerender): hAsync only returns promise if it has to
- Loading branch information
1 parent
dea56be
commit 25a547a
Showing
2 changed files
with
63 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
import * as d from '../../declarations'; | ||
import { h } from '@runtime'; | ||
import { isPromise } from '@utils'; | ||
import { consoleDevError } from '@platform'; | ||
|
||
export const hAsync = async (nodeName: any, vnodeData: any, ...children: d.ChildType[]) => { | ||
if (children) { | ||
children = await Promise.all(children); | ||
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)) { | ||
// has children and at least one of them is async | ||
// wait on all of them to be resolved | ||
return Promise.all(children) | ||
.then(resolvedChildren => { | ||
return h(nodeName, vnodeData, ...resolvedChildren); | ||
}) | ||
.catch(err => { | ||
consoleDevError(err); | ||
return h(nodeName, vnodeData); | ||
}); | ||
} | ||
|
||
// no async children, return sync | ||
return h(nodeName, vnodeData, ...children); | ||
} | ||
return h(nodeName, vnodeData, ...children); | ||
|
||
// no children, return sync | ||
return h(nodeName, vnodeData); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters