Skip to content

Commit

Permalink
call clear console history from the generated render code
Browse files Browse the repository at this point in the history
  • Loading branch information
AbanoubGhadban committed Oct 19, 2024
1 parent 585e5dc commit 2697ef7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
1 change: 1 addition & 0 deletions lib/react_on_rails/server_rendering_js_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ 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: 1 addition & 17 deletions 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 serverRenderReactComponentInternal(options: RenderParams): null | string | Promise<RenderResult> {
function serverRenderReactComponent(options: RenderParams): null | string | Promise<RenderResult> {
const { name: componentName, domNodeId, trace, props, railsContext, renderingReturnsPromises, throwJsErrors } = options;

let renderState: RenderState = {
Expand Down Expand Up @@ -180,20 +180,4 @@ function serverRenderReactComponentInternal(options: RenderParams): null | strin
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 2697ef7

Please sign in to comment.