Skip to content

Commit

Permalink
add comment about clearing console history
Browse files Browse the repository at this point in the history
  • Loading branch information
AbanoubGhadban committed Oct 19, 2024
1 parent 4caf257 commit 86d4262
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions node_package/src/serverRenderReactComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,15 @@ function serverRenderReactComponentInternal(options: RenderParams): null | strin
}

const serverRenderReactComponent: typeof serverRenderReactComponentInternal = (options) => {
let result: string | Promise<RenderResult> | null = null;
try {
result = serverRenderReactComponentInternal(options);
return serverRenderReactComponentInternal(options);
} finally {
// Reset console history after each render.
// See `RubyEmbeddedJavaScript.console_polyfill` for initialization.
// We don't need to clear the console history if the result is a promise
// Promises only supported in node renderer and node renderer takes care of cleanining console history
if (typeof result === 'string') {
console.history = [];
}
// This is necessary when ExecJS and old versions of node renderer are used.
// New versions of node renderer reset the console history automatically.
console.history = [];
}
return result;
};

export default serverRenderReactComponent;

0 comments on commit 86d4262

Please sign in to comment.