Skip to content

Commit

Permalink
Revert "call clear console history from the generated render code"
Browse files Browse the repository at this point in the history
This reverts commit 2697ef7.
  • Loading branch information
AbanoubGhadban committed Oct 19, 2024
1 parent 2697ef7 commit 4caf257
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/react_on_rails/server_rendering_js_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def render(props_string, rails_context, redux_stores, react_component_name, rend
var railsContext = #{rails_context};
#{redux_stores}
var props = #{props_string};
console.history = [];
return ReactOnRails.serverRenderReactComponent({
name: '#{react_component_name}',
domNodeId: '#{render_options.dom_id}',
Expand Down
18 changes: 17 additions & 1 deletion node_package/src/serverRenderReactComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function createFinalResult(
return JSON.stringify(createResultObject(result, consoleReplayScript, renderState));
}

function serverRenderReactComponent(options: RenderParams): null | string | Promise<RenderResult> {
function serverRenderReactComponentInternal(options: RenderParams): null | string | Promise<RenderResult> {
const { name: componentName, domNodeId, trace, props, railsContext, renderingReturnsPromises, throwJsErrors } = options;

let renderState: RenderState = {
Expand Down Expand Up @@ -180,4 +180,20 @@ function serverRenderReactComponent(options: RenderParams): null | string | Prom
return createFinalResult(renderState, componentName, throwJsErrors);
}

const serverRenderReactComponent: typeof serverRenderReactComponentInternal = (options) => {
let result: string | Promise<RenderResult> | null = null;
try {
result = 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 = [];
}
}
return result;
};

export default serverRenderReactComponent;

0 comments on commit 4caf257

Please sign in to comment.