Skip to content

Commit

Permalink
remove extra js eval call (#1544)
Browse files Browse the repository at this point in the history
* move try/finally internally
  • Loading branch information
wyattades authored Jul 17, 2023
1 parent fb3cce7 commit 005e26e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Changes since last non-beta release.

*Please add entries here for your pull requests that are not yet released.*

### Improved
- Improved performance by removing an unnecessary JS eval from Ruby. [PR 1544](https://github.com/shakacode/react_on_rails/pull/1544) by [wyattades](https://github.com/wyattades).

### Removed
- Removed a requirement for autoloaded pack files to be generated as part of CI or deployment separate from initial Shakapacker bundling. [PR 1545](https://github.com/shakacode/react_on_rails/pull/1545) by [judahmeek](https://github.com/judahmeek).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ def trace_js_code_used(msg, js_code, file_name = "tmp/server-generated.js", forc

def eval_js(js_code, _render_options)
@js_context_pool.with do |js_context|
result = js_context.eval(js_code)
js_context.eval("console.history = []")
result
js_context.eval(js_code)
end
end

Expand Down
13 changes: 12 additions & 1 deletion node_package/src/serverRenderReactComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import buildConsoleReplay from './buildConsoleReplay';
import handleError from './handleError';
import type { RenderParams, RenderResult, RenderingError } from './types/index';

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

let renderResult: null | string | Promise<string> = null;
Expand Down Expand Up @@ -153,3 +153,14 @@ as a renderFunction and not a simple React Function Component.`);

return JSON.stringify(result);
}

const serverRenderReactComponent: typeof serverRenderReactComponentInternal = (options) => {
try {
return serverRenderReactComponentInternal(options);
} finally {
// Reset console history after each render.
// See `RubyEmbeddedJavaScript.console_polyfill` for initialization.
console.history = [];
}
};
export default serverRenderReactComponent;

0 comments on commit 005e26e

Please sign in to comment.