Skip to content

Commit c4826d8

Browse files
committed
define a partial noop console api in server js context
1 parent dfeae79 commit c4826d8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/react/renderer.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ def self.render(component, args={})
2222
def self.combined_js
2323
@@combined_js ||= <<-CODE
2424
var global = global || this;
25+
26+
var console = global.console || {};
27+
['error', 'log', 'info', 'warn'].forEach(function (fn) {
28+
if (!(fn in console)) {
29+
console[fn] = function () {};
30+
}
31+
});
32+
2533
#{@@react_js};
2634
React = global.React;
2735
#{@@components_js};
@@ -48,4 +56,4 @@ def render(component, args={})
4856
end
4957

5058
end
51-
end
59+
end

test/react_renderer_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ class ReactRendererTest < ActiveSupport::TestCase
88
assert_match /data-react-checksum/, result
99
end
1010

11+
test 'Rendering does not throw an exception when console log api is used' do
12+
%W(error info log warn).each do |fn|
13+
assert_nothing_raised(ExecJS::ProgramError) do
14+
React::Renderer.pool.checkout.context.eval("console.#{fn}()")
15+
end
16+
end
17+
end
1118
end

0 commit comments

Comments
 (0)