Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no-turbolinks ci #244

Merged
merged 18 commits into from
Feb 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ AllCops:
Exclude:
- 'vendor/**/*'
- 'spec/fixtures/**/*'
- 'node_modules/**/*.*'
- 'node_modules/**/.*'
- 'node_modules/**/*'
- 'coverage/**/*'
- 'db/**/*'
- 'db/schema.rb'
- 'db/seeds.rb'
- 'client/node_modules/**/*.*'
- 'client/node_modules/**/*'
- 'client/node_modules/**/.*'
- 'bin/**/*'
- !ruby/regexp /old_and_unused\.rb$/
- 'spec/react_on_rails/dummy-for-generators/**/*'
- 'spec/dummy/bin/**/*'
- 'spec/dummy/client/node_modules/**/*'
- 'spec/dummy/client/node_modules/**/.*'
- 'gen-examples/examples/**/.*'
- 'gen-examples/examples/**/*'

Metrics/LineLength:
Expand Down
33 changes: 29 additions & 4 deletions lib/react_on_rails/server_rendering_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def self.server_render_js_with_console_logging(js_code)
class << self
private

def trace_messsage(js_code)
def trace_messsage(js_code, file_name = "tmp/server-generated.js")
return unless ENV["TRACE_REACT_ON_RAILS"].present?
# Set to anything to print generated code.
puts "Z" * 80
puts "react_renderer.rb: 92"
puts "wrote file tmp/server-generated.js"
File.write("tmp/server-generated.js", js_code)
puts "wrote file #{file_name}"
File.write(file_name, js_code)
puts "Z" * 80
end

Expand All @@ -75,9 +75,22 @@ def create_js_context
bundle_js_code = File.read(server_js_file)
base_js_code = <<-JS
#{console_polyfill}
#{execjs_timer_polyfills}
#{bundle_js_code};
JS
ExecJS.compile(base_js_code)
begin
ExecJS.compile(base_js_code)
rescue => e
file_name = "tmp/base_js_code.js"
msg = "ERROR when compiling base_js_code! See #{file_name} to "\
"ERROR when compiling base_js_code! See #{file_name} to "\
"correlate line numbers of error. Error is\n\n#{e.message}"\
"\n\n#{e.backtrace.join("\n")}"
puts msg
Rails.logger.error(msg)
trace_messsage(base_js_code, file_name)
raise e
end
else
if server_js_file.present?
msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be "\
Expand All @@ -90,6 +103,18 @@ def create_js_context
end
end

def execjs_timer_polyfills
<<-JS
function setInterval() {
console.error('setInterval is not defined for execJS. See https://github.com/sstephenson/execjs#faq');
}

function setTimeout() {
console.error('setTimeout is not defined for execJS. See https://github.com/sstephenson/execjs#faq');
}
JS
end

# Reimplement console methods for replaying on the client
def console_polyfill
<<-JS
Expand Down
1 change: 1 addition & 0 deletions lib/react_on_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module ReactOnRails
VERSION = "2.2.0".freeze
end
4 changes: 2 additions & 2 deletions node_package/src/clientStartup.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ export default function clientStartup(context) {
// Webpack bundles first.

if (!turbolinksInstalled()) {
debugTurbolinks('WITHOUT TURBOLINKS: DOMContentLoaded handler installed.');
debugTurbolinks('NOT USING TURBOLINKS: DOMContentLoaded event, calling reactOnRailsPageLoaded');
reactOnRailsPageLoaded();
} else {
debugTurbolinks('WITH TURBOLINKS: document page:before-unload and page:change handlers' +
debugTurbolinks('USING TURBOLINKS: document page:before-unload and page:change handlers' +
' installed.');
document.addEventListener('page:before-unload', reactOnRailsPageUnloaded);
document.addEventListener('page:change', reactOnRailsPageLoaded);
Expand Down
Loading