Skip to content

Commit d4d5c94

Browse files
committed
Enable SSR for HelloWorld
1. Turn on prerender: true so component server renders, viewable the "view page source" for http://localhost:3000/hello_world 2. React on Rails config needs to set for using the same bundle for client and server rendering. 3. Due to the rails/webpacker importing the HMR: true and inline: true in v5.1, we need to disable those. 4. We can only run this using the foreman start -f Procfile.dev because HMR will not work with SSR until we have a separate bundle for SSR.
1 parent bdfd850 commit d4d5c94

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

app/views/hello_world/index.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<h1>Hello World</h1>
2-
<%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %>
2+
<%= react_component("HelloWorld", props: @hello_world_props, prerender: true) %>

config/initializers/react_on_rails.rb

+2
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@
4242
# React components.
4343
#
4444
config.server_bundle_js_file = "hello-world-bundle.js"
45+
46+
config.same_bundle_for_client_and_server = true
4547
end

config/webpacker.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ development:
6060
host: localhost
6161
port: 3035
6262
public: localhost:3035
63-
hmr: true
63+
hmr: false
6464
# Inline should be set to true if using HMR
65-
inline: true
65+
inline: false
6666
overlay: true
6767
compress: true
6868
disable_host_check: true

0 commit comments

Comments
 (0)