Skip to content

Commit

Permalink
enable webpack-dev-server & ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
Judahmeek committed Dec 5, 2018
1 parent b4d3763 commit f1be0ba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Change Log
All notable changes to this project's source code will be documented in this file. Items under `Unreleased` is upcoming features that will be out in next version. NOTE: major versions of the npm module and the gem must be kept in sync.

Migration instructions for the major updates can be found [here](docs/basics/upgrading-react-on-rails.md#upgrading-to-version-9.md). Some smaller migration information can be found here.
Migration instructions for the major updates can be found [here](docs/basics/upgrading-react-on-rails.md#upgrading-to-version-9.md). Some smaller migration information can be found here.

## Need Help Migrating?
If you would like help in migrating between React on Rails versions or help with implementing server rendering, please contact [[email protected]](mailto:[email protected]) for information about our [ShakaCode Pro Support](https://www.shakacode.com/work/shakacode-pro-support.pdf).
Expand All @@ -20,6 +20,8 @@ Changes since last non-beta release.
#### Improved
- To support React v16, updated API for manually calling `ReactOnRails.render(name, props, domNodeId, hydrate)`. Added 3rd @param hydrate Pass truthy to update server rendered html. Default is falsey Any truthy values calls hydrate rather than render. (https://github.com/shakacode/react_on_rails/pull/1159) by [justin808](https://github.com/justin808) and [coopersamuel](https://github.com/coopersamuel).

- Enabled the use of webpack-dev-server with Server-side rendering. (https://github.com/shakacode/react_on_rails/pull/1173) by [justin808](https://github.com/justin808) and [judahmeek](https://github.com/judahmeek).

### [11.1.8] - 2018-10-14

#### Improved
Expand Down Expand Up @@ -54,7 +56,7 @@ Changes since last non-beta release.

#### Fixed
- Tests now properly exit if the config.build_test_command fails!
- Source path for project using Webpacker would default to "app/javascript" even if when the node_modules
- Source path for project using Webpacker would default to "app/javascript" even if when the node_modules
directory was set to "client". Fix now makes the configuration of this crystal clear.
- renamed method RenderOptions.has_random_dom_id? to RenderOptions.random_dom_id? for rubocop rule.
[PR 1133](https://github.com/shakacode/react_on_rails/pull/1133) by [justin808](https://github.com/justin808)
Expand Down
4 changes: 1 addition & 3 deletions lib/react_on_rails/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,7 @@ def props_string(props)

# Returns object with values that are NOT html_safe!
def server_rendered_react_component(render_options)
if !render_options.prerender || ReactOnRails::Utils.server_bundle_path_is_http?
return { "html" => "", "consoleReplayScript" => "" }
end
return { "html" => "", "consoleReplayScript" => "" } unless render_options.prerender

react_component_name = render_options.react_component_name
props = render_options.props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

module ReactOnRails
module ServerRenderingPool
# rubocop:disable Metrics/ClassLength
class RubyEmbeddedJavaScript
# rubocop:enable Metrics/ClassLength
class << self
def reset_pool
options = {
Expand All @@ -17,12 +19,16 @@ def reset_pool
def reset_pool_if_server_bundle_was_modified
return unless ReactOnRails.configuration.development_mode

file_mtime = File.mtime(ReactOnRails::Utils.server_bundle_js_file_path)
@server_bundle_timestamp ||= file_mtime
return if @server_bundle_timestamp == file_mtime

@server_bundle_timestamp = file_mtime
if ReactOnRails::Utils.server_bundle_path_is_http?
return if @server_bundle_url == ReactOnRails::Utils.server_bundle_js_file_path
@server_bundle_url = ReactOnRails::Utils.server_bundle_js_file_path
else
file_mtime = File.mtime(ReactOnRails::Utils.server_bundle_js_file_path)
@server_bundle_timestamp ||= file_mtime
return if @server_bundle_timestamp == file_mtime

@server_bundle_timestamp = file_mtime
end
ReactOnRails::ServerRenderingPool.reset_pool
end

Expand Down Expand Up @@ -97,7 +103,11 @@ def eval_js(js_code, _render_options)

def read_bundle_js_code
server_js_file = ReactOnRails::Utils.server_bundle_js_file_path
File.read(server_js_file)
if ReactOnRails::Utils.server_bundle_path_is_http?
Net::HTTP.get(URI.parse(server_js_file)).force_encoding('UTF-8')
else
File.read(server_js_file)
end
rescue StandardError => e
msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be "\
"read. You may set the server_bundle_js_file in your configuration to be \"\" to "\
Expand Down

0 comments on commit f1be0ba

Please sign in to comment.