@@ -17,8 +17,8 @@ export const renderPageToHtml = async (
17
17
res : ServerResponse ,
18
18
renderMode ?: "export" | "passthrough" | true
19
19
) =>
20
- | PromiseLike < { renderOpts : Record < string , any > ; html : string } >
21
- | { renderOpts : Record < string , any > ; html : string } ;
20
+ | PromiseLike < { renderOpts : Record < string , any > ; html : any } >
21
+ | { renderOpts : Record < string , any > ; html : any } ;
22
22
} ,
23
23
req : IncomingMessage ,
24
24
res : ServerResponse ,
@@ -30,24 +30,24 @@ export const renderPageToHtml = async (
30
30
renderMode
31
31
) ;
32
32
33
- let html ;
34
- try {
35
- if ( typeof htmlResult === "string" ) {
36
- html = htmlResult ; // Next.js < 11.1
37
- } else {
38
- html = htmlResult ? await resultsToString ( [ htmlResult ] ) : "" ; // Next >= 11.1.1
33
+ let html = undefined ;
34
+ if ( typeof htmlResult === "string" ) {
35
+ html = htmlResult ; // Next.js < 11.1
36
+ } else {
37
+ if ( htmlResult ) {
38
+ html = await htmlResult . toUnchunkedString ?.( ) ; // Next >= 12
39
+
40
+ if ( ! html ) {
41
+ try {
42
+ html = await resultsToString ( [ htmlResult ] ) ; // Next >= 11.1.1
43
+ } catch ( e ) {
44
+ console . log ( "html could not be rendered using resultsToString()." ) ;
45
+ }
46
+ }
39
47
}
40
- } catch ( e ) {
41
- // Fallback to using renderReqToHtml without renderMode specified,
42
- // which will render html based on the page's renderReqToHtml,
43
- // which should always work (but adds another *warm* render cost)
44
- console . log (
45
- "Exception occurred, falling back to using page's rendering function for html"
46
- ) ;
47
- html = ( await page . renderReqToHTML ( req , res ) ) as unknown as string ;
48
48
}
49
49
50
- if ( ! html || html === "" ) {
50
+ if ( ! html ) {
51
51
console . log (
52
52
"html is empty, falling back to using page's rendering function for html"
53
53
) ;
0 commit comments