@@ -99,7 +99,6 @@ as a renderFunction and not a simple React Function Component.`);
99
99
renderingError = e ;
100
100
}
101
101
102
- const consoleReplayScript = buildConsoleReplay ( ) ;
103
102
const addRenderingErrors = ( resultObject : RenderResult , renderError : RenderingError ) => {
104
103
resultObject . renderingError = { // eslint-disable-line no-param-reassign
105
104
message : renderError . message ,
@@ -114,7 +113,7 @@ as a renderFunction and not a simple React Function Component.`);
114
113
try {
115
114
promiseResult = {
116
115
html : await renderResult ,
117
- consoleReplayScript,
116
+ consoleReplayScript : buildConsoleReplay ( ) ,
118
117
hasErrors,
119
118
} ;
120
119
} catch ( e : any ) {
@@ -127,7 +126,7 @@ as a renderFunction and not a simple React Function Component.`);
127
126
name,
128
127
serverSide : true ,
129
128
} ) ,
130
- consoleReplayScript,
129
+ consoleReplayScript : buildConsoleReplay ( ) ,
131
130
hasErrors : true ,
132
131
}
133
132
renderingError = e ;
@@ -145,7 +144,7 @@ as a renderFunction and not a simple React Function Component.`);
145
144
146
145
const result = {
147
146
html : renderResult ,
148
- consoleReplayScript,
147
+ consoleReplayScript : buildConsoleReplay ( ) ,
149
148
hasErrors,
150
149
} as RenderResult ;
151
150
@@ -157,12 +156,20 @@ as a renderFunction and not a simple React Function Component.`);
157
156
}
158
157
159
158
const serverRenderReactComponent : typeof serverRenderReactComponentInternal = ( options ) => {
159
+ let result : string | Promise < RenderResult > | null = null ;
160
160
try {
161
- return serverRenderReactComponentInternal ( options ) ;
161
+ result = serverRenderReactComponentInternal ( options ) ;
162
162
} finally {
163
163
// Reset console history after each render.
164
164
// See `RubyEmbeddedJavaScript.console_polyfill` for initialization.
165
- console . history = [ ] ;
165
+ if ( ! result || typeof ( result ) === 'string' ) {
166
+ console . history = [ ] ;
167
+ } else {
168
+ result . finally ( ( ) => {
169
+ console . history = [ ] ;
170
+ } ) ;
171
+ }
166
172
}
173
+ return result ;
167
174
} ;
168
175
export default serverRenderReactComponent ;
0 commit comments