1
1
import { h , options , cloneElement } from 'preact' ;
2
- import renderToString from 'preact-render-to-string' ;
2
+ import { renderToStringAsync } from 'preact-render-to-string' ;
3
3
4
4
let vnodeHook ;
5
5
@@ -12,32 +12,19 @@ options.vnode = vnode => {
12
12
/**
13
13
* @param {ReturnType<h> } vnode The root JSX element to render (eg: `<App />`)
14
14
* @param {object } [options]
15
- * @param {number } [options.maxDepth = 10] The maximum number of nested asynchronous operations to wait for before flushing
16
15
* @param {object } [options.props] Additional props to merge into the root JSX element
17
16
*/
18
17
export default async function prerender ( vnode , options ) {
19
18
options = options || { } ;
20
19
21
- const maxDepth = options . maxDepth || 10 ;
22
20
const props = options . props ;
23
- let tries = 0 ;
24
21
25
22
if ( typeof vnode === 'function' ) {
26
23
vnode = h ( vnode , props ) ;
27
24
} else if ( props ) {
28
25
vnode = cloneElement ( vnode , props ) ;
29
26
}
30
27
31
- const render = ( ) => {
32
- if ( ++ tries > maxDepth ) return ;
33
- try {
34
- return renderToString ( vnode ) ;
35
- } catch ( e ) {
36
- if ( e && e . then ) return e . then ( render ) ;
37
- throw e ;
38
- }
39
- } ;
40
-
41
28
let links = new Set ( ) ;
42
29
vnodeHook = ( { type, props } ) => {
43
30
if ( type === 'a' && props && props . href && ( ! props . target || props . target === '_self' ) ) {
@@ -46,7 +33,7 @@ export default async function prerender(vnode, options) {
46
33
} ;
47
34
48
35
try {
49
- let html = await render ( ) ;
36
+ let html = await renderToStringAsync ( vnode ) ;
50
37
html += `<script type="isodata"></script>` ;
51
38
return { html, links } ;
52
39
} finally {
0 commit comments