We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents a89d84f + e199d3f commit c2d6827Copy full SHA for c2d6827
lib/react/rails/component_mount.rb
@@ -46,7 +46,15 @@ def react_component(name, props = {}, options = {}, &block)
46
# remove internally used properties so they aren't rendered to DOM
47
html_options.except!(:tag, :prerender, :camelize_props)
48
49
- content_tag(html_tag, '', html_options, &block)
+ rendered_tag = content_tag(html_tag, '', html_options, &block)
50
+ if React::ServerRendering.renderer_options[:replay_console]
51
+ # Grab the server-rendered console replay script
52
+ # and move it _outside_ the container div
53
+ rendered_tag.sub!(/\n(<script class="react-rails-console-replay">.*<\/script>)<\/(\w+)>$/m,'</2円>1円')
54
+ rendered_tag.html_safe
55
+ else
56
+ rendered_tag
57
+ end
58
end
59
60
private
lib/react/server_rendering.rb
@@ -7,6 +7,8 @@ module ServerRendering
7
mattr_accessor :renderer, :renderer_options,
8
:pool_size, :pool_timeout
9
10
+ self.renderer_options = {}
11
+
12
# Discard the old ConnectionPool & create a new one
13
def self.reset_pool
14
options = {size: pool_size, timeout: pool_timeout}
lib/react/server_rendering/bundle_renderer/console_replay.js
@@ -1,6 +1,6 @@
1
(function (history) {
2
if (history && history.length > 0) {
3
- result += '\n<scr'+'ipt>';
+ result += '\n<scr'+'ipt>';
4
history.forEach(function (msg) {
5
result += '\nconsole.' + msg.level + '.apply(console, ' + JSON.stringify(msg.arguments) + ');';
6
});
test/dummy/app/javascript/components/TodoList.js
@@ -8,6 +8,7 @@ module.exports = React.createClass({
this.setState({mounted: 'yep'});
},
render: function() {
+ console.log("Test Console Replay")
return (
<ul>
<li id='status'>{this.state.mounted}</li>
test/dummy/config/application.rb
@@ -32,6 +32,10 @@ class Application < Rails::Application
32
# config.i18n.default_locale = :de
33
config.react.variant = :production
34
config.react.addons = false
35
+ config.react.server_renderer_options = {
36
+ replay_console: true,
37
+ }
38
39
if SprocketsHelpers.available?
40
config.assets.enabled = true
41
test/react/server_rendering/bundle_renderer_test.rb
@@ -49,7 +49,7 @@ class BundleRendererTest < ActiveSupport::TestCase
test '#render replays console messages' do
result = @renderer.render("TodoListWithConsoleLog", {todos: ["log some messages"]}, nil)
- assert_match(/<script>$/, result)
+ assert_match(/<script>$/, result)
assert_match(/console.log.apply\(console, \["got initial state"\]\);$/, result)
assert_match(/console.warn.apply\(console, \["mounted component"\]\);$/, result)
assert_match(/console.error.apply\(console, \["rendered!","foo"\]\);$/, result)
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments