rails-react-ssr 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -2
- data/lib/rails_react_ssr/server_runner.rb +8 -8
- data/lib/rails_react_ssr/version.rb +1 -1
- data/test/webpacker_utils_test.rb +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ad59fce8226f5e73736449a5a2b85930470960916ff111dc4acb8b71066a525
|
4
|
+
data.tar.gz: d705798c238dc41fcfb5a3299b1e7289c9d3e366a80095bc4330abdfb8687b3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0edf899b630e4a184844fa8758ea823cd5964d35883800247112360145c5f2b6dc790ec1588dbbeccf0280b037e0d4edccdb14069c6463ab62ef3c2a5ee5a9e2
|
7
|
+
data.tar.gz: 6bf7ea4daf87400c26541ed101b192a848623439ecef8a9edbfbae10f37a2e0296a3bf80f110c3340b7c74dce23c4e5b08ca0ceb06403894faaade9b2a963b5d
|
data/README.md
CHANGED
@@ -5,8 +5,9 @@ RailsReactSSR is a light weight JS server side rendering utility that takes adva
|
|
5
5
|
## Motivation
|
6
6
|
|
7
7
|
In my latest project I designed my application to use Rails for my API endpoints and `ReactJS` with `react-router` to
|
8
|
-
handle routing and handle the front end. I needed a basic tool that would not add a lot of bloat
|
9
|
-
server side rendering while allowing me to process the response (i.e. handle redirects from the router)
|
8
|
+
handle routing and handle the front end. I needed a basic tool that would not add a lot of bloat, be able to handle
|
9
|
+
server side rendering while allowing me to process the response (i.e. handle redirects from the router) and did not
|
10
|
+
force me to use any packages or make decisions for me on how to structure my ReactJS code.
|
10
11
|
|
11
12
|
## Dependencies
|
12
13
|
|
@@ -175,6 +176,19 @@ end
|
|
175
176
|
|
176
177
|
```
|
177
178
|
|
179
|
+
## Common Issues with SSR and Rails
|
180
|
+
|
181
|
+
### I'm unable to execute code with webpacker-dev-server running.
|
182
|
+
|
183
|
+
The `webpacker-dev-server` injects a websocket when `inline` or `hmr` flags are set to true in for the `dev_server`
|
184
|
+
configuration in `webpacker.yml`. Make sure these are set to **false** if you plan on implementing SSR.
|
185
|
+
|
186
|
+
### `document` or `window` is not defined
|
187
|
+
|
188
|
+
Global objects like `document` or `window` that are specific to browsers are not set when running the javascript on
|
189
|
+
the server; so it's best to wrap any code, or avoid using it outside of `componentDidMount`, `componentDidUpdate` or
|
190
|
+
`componentWillUnmount`.
|
191
|
+
|
178
192
|
## Alternatives
|
179
193
|
|
180
194
|
There are several alternatives that are more comprehensive and might be a better fit for your use case:
|
@@ -35,12 +35,6 @@ const recordedLogs = [];
|
|
35
35
|
def self.exec!(bundle, props: {}, outputTemp: false, max_tries: 10, delay: 1000)
|
36
36
|
bundle_file = RailsReactSSR::WebpackerUtils.open_bundle bundle, max_tries: max_tries, delay: delay
|
37
37
|
|
38
|
-
## Format the properties for js
|
39
|
-
jsProps = props.inject({}) do |hash,(k,v)|
|
40
|
-
hash[k.to_s.camelcase.gsub(/\A./, &:downcase)] = v
|
41
|
-
hash
|
42
|
-
end
|
43
|
-
|
44
38
|
status = 0
|
45
39
|
output = nil
|
46
40
|
|
@@ -49,7 +43,7 @@ const recordedLogs = [];
|
|
49
43
|
|
50
44
|
begin
|
51
45
|
write_console_polyfill js
|
52
|
-
write_props_polyfill js,
|
46
|
+
write_props_polyfill js, props
|
53
47
|
write_bundle js, bundle_file
|
54
48
|
|
55
49
|
js.flush
|
@@ -101,8 +95,14 @@ const recordedLogs = [];
|
|
101
95
|
end
|
102
96
|
|
103
97
|
def self.write_props_polyfill(temp_file, props)
|
98
|
+
## Format the properties for js
|
99
|
+
jsProps = props.inject({}) do |hash,(k,v)|
|
100
|
+
hash[k.to_s.camelcase.gsub(/\A./, &:downcase)] = v
|
101
|
+
hash
|
102
|
+
end
|
103
|
+
|
104
104
|
temp_file.write <<-JS
|
105
|
-
const serverProps = #{ActiveSupport::JSON.encode
|
105
|
+
const serverProps = #{ActiveSupport::JSON.encode jsProps};
|
106
106
|
|
107
107
|
JS
|
108
108
|
end
|
@@ -13,7 +13,7 @@ class RailsReactSSR::WebpackerUtilsTest < RailsReactSSR::Test
|
|
13
13
|
|
14
14
|
def test_bundle_found!
|
15
15
|
assert_equal RailsReactSSR::WebpackerUtils.hashed_bundle_name!('application.js'),
|
16
|
-
|
16
|
+
'/packs/application-k344a6d59eef8632c9d1.js'
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_open_local_file
|
@@ -29,6 +29,15 @@ class RailsReactSSR::WebpackerUtilsTest < RailsReactSSR::Test
|
|
29
29
|
skip 'Need to find a way to run the dev server during the tests'
|
30
30
|
end
|
31
31
|
|
32
|
+
def test_build_remote_uri
|
33
|
+
with_rails_env 'development' do
|
34
|
+
hashed_bundle = '/packs/application-k344a6d59eef8632c9d1.js'
|
35
|
+
uri = RailsReactSSR::WebpackerUtils.send :dev_bundle_uri, hashed_bundle
|
36
|
+
|
37
|
+
assert_equal uri, 'http://localhost:3035/packs/application-k344a6d59eef8632c9d1.js'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
32
41
|
private
|
33
42
|
|
34
43
|
def raw_application_js
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-react-ssr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Fawks
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webpacker
|