Skip to content

Commit

Permalink
Enable SSR for HelloWorld
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
justin808 committed Aug 3, 2020
1 parent bdfd850 commit d4d5c94
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/views/hello_world/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h1>Hello World</h1>
<%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %>
<%= react_component("HelloWorld", props: @hello_world_props, prerender: true) %>
2 changes: 2 additions & 0 deletions config/initializers/react_on_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@
# React components.
#
config.server_bundle_js_file = "hello-world-bundle.js"

config.same_bundle_for_client_and_server = true
end
4 changes: 2 additions & 2 deletions config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ development:
host: localhost
port: 3035
public: localhost:3035
hmr: true
hmr: false
# Inline should be set to true if using HMR
inline: true
inline: false
overlay: true
compress: true
disable_host_check: true
Expand Down

0 comments on commit d4d5c94

Please sign in to comment.