Skip to content

Commit d75ed4d

Browse files
committed
Add Propshaft server rendering support
1 parent 3b69603 commit d75ed4d

File tree

10 files changed

+358
-1
lines changed

10 files changed

+358
-1
lines changed

.github/workflows/ruby.yml

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ jobs:
7373
- base
7474
- shakapacker
7575
# These don't have shakapacker:
76+
- propshaft
7677
- sprockets_3
7778
- sprockets_4
7879
runs-on: ubuntu-latest

Appraisals

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
appraise 'propshaft' do
2+
gem 'propshaft', '~> 1.0.x'
3+
end
4+
15
appraise 'sprockets_4' do
26
gem 'sprockets', '~> 4.0.x'
37
gem 'sprockets-rails'

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog for React-Rails
22

3-
If you need help upgrading `react-rails`, `webpacker` to `shakapacker`, or JS packages, contact [email protected]. We can upgrade your project and improve your development and customer experiences, allowing you to focus on building new features or fixing bugs instead.
3+
If you need help upgrading `react-rails`, `webpacker` to `shakapacker`, or JS packages, contact [email protected]. We can upgrade your project and improve your development and customer experiences, allowing you to focus on building new features or fixing bugs instead.
44

55
For an overview of working with us, see our [Client Engagement Model](https://www.shakacode.com/blog/client-engagement-model/) article and [how we bill for time](https://www.shakacode.com/blog/shortcut-jira-trello-github-toggl-time-and-task-tracking/).
66

@@ -15,6 +15,8 @@ Changes since the last non-beta release.
1515

1616
_Please add entries here for your pull requests that have not yet been released. Include LINKS for PRs and committers._
1717

18+
- Support for Propshaft server rendering.
19+
1820
## [3.2.1] - 2024-05-16
1921

2022
#### Fixed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ For version 2.7 documentation, visit the [2.7-stable](https://github.com/reactjs
1010
React-Rails is a flexible tool to use [React](http://facebook.github.io/react/) with Rails. The benefits:
1111
* Automatically renders React server-side and client-side
1212
* Supports [Shakapacker](https://github.com/shakacode/shakapacker) v7
13+
* Supports Propshaft
1314
* Supports Sprockets 4.x, 3.x
1415
* Lets you use [JSX](http://facebook.github.io/react/docs/jsx-in-depth.html), [ES6](http://es6-features.org/), [TypeScript](https://www.typescriptlang.org/), [CoffeeScript](http://coffeescript.org/)
1516

gemfiles/propshaft.gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file was generated by Appraisal
2+
3+
source "http://rubygems.org"
4+
5+
gem "propshaft", "~> 1.0.x"
6+
7+
gemspec path: "../"

gemfiles/propshaft.gemfile.lock

+289
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
PATH
2+
remote: ..
3+
specs:
4+
react-rails (3.2.0)
5+
babel-transpiler (>= 0.7.0)
6+
connection_pool
7+
execjs
8+
railties (>= 3.2)
9+
tilt
10+
11+
GEM
12+
remote: http://rubygems.org/
13+
specs:
14+
actioncable (7.0.8.1)
15+
actionpack (= 7.0.8.1)
16+
activesupport (= 7.0.8.1)
17+
nio4r (~> 2.0)
18+
websocket-driver (>= 0.6.1)
19+
actionmailbox (7.0.8.1)
20+
actionpack (= 7.0.8.1)
21+
activejob (= 7.0.8.1)
22+
activerecord (= 7.0.8.1)
23+
activestorage (= 7.0.8.1)
24+
activesupport (= 7.0.8.1)
25+
mail (>= 2.7.1)
26+
net-imap
27+
net-pop
28+
net-smtp
29+
actionmailer (7.0.8.1)
30+
actionpack (= 7.0.8.1)
31+
actionview (= 7.0.8.1)
32+
activejob (= 7.0.8.1)
33+
activesupport (= 7.0.8.1)
34+
mail (~> 2.5, >= 2.5.4)
35+
net-imap
36+
net-pop
37+
net-smtp
38+
rails-dom-testing (~> 2.0)
39+
actionpack (7.0.8.1)
40+
actionview (= 7.0.8.1)
41+
activesupport (= 7.0.8.1)
42+
rack (~> 2.0, >= 2.2.4)
43+
rack-test (>= 0.6.3)
44+
rails-dom-testing (~> 2.0)
45+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
46+
actiontext (7.0.8.1)
47+
actionpack (= 7.0.8.1)
48+
activerecord (= 7.0.8.1)
49+
activestorage (= 7.0.8.1)
50+
activesupport (= 7.0.8.1)
51+
globalid (>= 0.6.0)
52+
nokogiri (>= 1.8.5)
53+
actionview (7.0.8.1)
54+
activesupport (= 7.0.8.1)
55+
builder (~> 3.1)
56+
erubi (~> 1.4)
57+
rails-dom-testing (~> 2.0)
58+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
59+
activejob (7.0.8.1)
60+
activesupport (= 7.0.8.1)
61+
globalid (>= 0.3.6)
62+
activemodel (7.0.8.1)
63+
activesupport (= 7.0.8.1)
64+
activerecord (7.0.8.1)
65+
activemodel (= 7.0.8.1)
66+
activesupport (= 7.0.8.1)
67+
activestorage (7.0.8.1)
68+
actionpack (= 7.0.8.1)
69+
activejob (= 7.0.8.1)
70+
activerecord (= 7.0.8.1)
71+
activesupport (= 7.0.8.1)
72+
marcel (~> 1.0)
73+
mini_mime (>= 1.1.0)
74+
activesupport (7.0.8.1)
75+
concurrent-ruby (~> 1.0, >= 1.0.2)
76+
i18n (>= 1.6, < 2)
77+
minitest (>= 5.1)
78+
tzinfo (~> 2.0)
79+
addressable (2.8.1)
80+
public_suffix (>= 2.0.2, < 6.0)
81+
appraisal (2.4.1)
82+
bundler
83+
rake
84+
thor (>= 0.14.0)
85+
babel-source (5.8.35)
86+
babel-transpiler (0.7.0)
87+
babel-source (>= 4.0, < 6)
88+
execjs (~> 2.0)
89+
builder (3.2.4)
90+
byebug (11.1.3)
91+
capybara (3.38.0)
92+
addressable
93+
matrix
94+
mini_mime (>= 0.1.3)
95+
nokogiri (~> 1.8)
96+
rack (>= 1.6.0)
97+
rack-test (>= 0.6.3)
98+
regexp_parser (>= 1.5, < 3.0)
99+
xpath (~> 3.2)
100+
codeclimate-test-reporter (1.0.9)
101+
simplecov (<= 0.13)
102+
coderay (1.1.3)
103+
coffee-rails (5.0.0)
104+
coffee-script (>= 2.2.0)
105+
railties (>= 5.2.0)
106+
coffee-script (2.4.1)
107+
coffee-script-source
108+
execjs
109+
coffee-script-source (1.12.2)
110+
concurrent-ruby (1.2.2)
111+
connection_pool (2.4.0)
112+
crass (1.0.6)
113+
date (3.3.4)
114+
docile (1.1.5)
115+
erubi (1.12.0)
116+
es5-shim-rails (4.0.1)
117+
actionpack (>= 3.1)
118+
railties (>= 3.1)
119+
execjs (2.8.1)
120+
ffi (1.15.5)
121+
formatador (1.1.0)
122+
gem-release (2.2.2)
123+
globalid (1.1.0)
124+
activesupport (>= 5.0)
125+
guard (2.18.0)
126+
formatador (>= 0.2.4)
127+
listen (>= 2.7, < 4.0)
128+
lumberjack (>= 1.0.12, < 2.0)
129+
nenv (~> 0.1)
130+
notiffany (~> 0.0)
131+
pry (>= 0.13.0)
132+
shellany (~> 0.0)
133+
thor (>= 0.18.1)
134+
guard-compat (1.2.1)
135+
guard-minitest (2.4.6)
136+
guard-compat (~> 1.2)
137+
minitest (>= 3.0)
138+
i18n (1.13.0)
139+
concurrent-ruby (~> 1.0)
140+
jbuilder (2.11.5)
141+
actionview (>= 5.0.0)
142+
activesupport (>= 5.0.0)
143+
json (2.6.3)
144+
listen (3.0.8)
145+
rb-fsevent (~> 0.9, >= 0.9.4)
146+
rb-inotify (~> 0.9, >= 0.9.7)
147+
loofah (2.21.1)
148+
crass (~> 1.0.2)
149+
nokogiri (>= 1.5.9)
150+
lumberjack (1.2.8)
151+
mail (2.8.1)
152+
mini_mime (>= 0.1.1)
153+
net-imap
154+
net-pop
155+
net-smtp
156+
marcel (1.0.4)
157+
matrix (0.4.2)
158+
method_source (1.0.0)
159+
mini_mime (1.1.2)
160+
minitest (5.18.0)
161+
minitest-retry (0.2.2)
162+
minitest (>= 5.0)
163+
nenv (0.3.0)
164+
net-imap (0.4.11)
165+
date
166+
net-protocol
167+
net-pop (0.1.2)
168+
net-protocol
169+
net-protocol (0.2.2)
170+
timeout
171+
net-smtp (0.5.0)
172+
net-protocol
173+
nio4r (2.7.3)
174+
nokogiri (1.14.3-x86_64-darwin)
175+
racc (~> 1.4)
176+
nokogiri (1.14.3-x86_64-linux)
177+
racc (~> 1.4)
178+
notiffany (0.1.3)
179+
nenv (~> 0.1)
180+
shellany (~> 0.0)
181+
package_json (0.1.0)
182+
propshaft (1.1.0)
183+
actionpack (>= 7.0.0)
184+
activesupport (>= 7.0.0)
185+
rack
186+
railties (>= 7.0.0)
187+
pry (0.14.2)
188+
coderay (~> 1.1)
189+
method_source (~> 1.0)
190+
pry-byebug (3.10.1)
191+
byebug (~> 11.0)
192+
pry (>= 0.13, < 0.15)
193+
public_suffix (5.0.1)
194+
racc (1.6.2)
195+
rack (2.2.7)
196+
rack-proxy (0.7.7)
197+
rack
198+
rack-test (2.1.0)
199+
rack (>= 1.3)
200+
rails (7.0.8.1)
201+
actioncable (= 7.0.8.1)
202+
actionmailbox (= 7.0.8.1)
203+
actionmailer (= 7.0.8.1)
204+
actionpack (= 7.0.8.1)
205+
actiontext (= 7.0.8.1)
206+
actionview (= 7.0.8.1)
207+
activejob (= 7.0.8.1)
208+
activemodel (= 7.0.8.1)
209+
activerecord (= 7.0.8.1)
210+
activestorage (= 7.0.8.1)
211+
activesupport (= 7.0.8.1)
212+
bundler (>= 1.15.0)
213+
railties (= 7.0.8.1)
214+
rails-dom-testing (2.0.3)
215+
activesupport (>= 4.2.0)
216+
nokogiri (>= 1.6)
217+
rails-html-sanitizer (1.5.0)
218+
loofah (~> 2.19, >= 2.19.1)
219+
railties (7.0.8.1)
220+
actionpack (= 7.0.8.1)
221+
activesupport (= 7.0.8.1)
222+
method_source
223+
rake (>= 12.2)
224+
thor (~> 1.0)
225+
zeitwerk (~> 2.5)
226+
rake (13.0.6)
227+
rb-fsevent (0.11.2)
228+
rb-inotify (0.10.1)
229+
ffi (~> 1.0)
230+
regexp_parser (2.7.0)
231+
rexml (3.2.6)
232+
rubyzip (2.3.2)
233+
selenium-webdriver (4.9.0)
234+
rexml (~> 3.2, >= 3.2.5)
235+
rubyzip (>= 1.2.2, < 3.0)
236+
websocket (~> 1.0)
237+
semantic_range (3.0.0)
238+
shellany (0.0.1)
239+
simplecov (0.13.0)
240+
docile (~> 1.1.0)
241+
json (>= 1.8, < 3)
242+
simplecov-html (~> 0.10.0)
243+
simplecov-html (0.10.2)
244+
test-unit (2.5.5)
245+
thor (1.2.2)
246+
tilt (2.2.0)
247+
timeout (0.4.1)
248+
turbo-rails (2.0.5)
249+
actionpack (>= 6.0.0)
250+
activejob (>= 6.0.0)
251+
railties (>= 6.0.0)
252+
tzinfo (2.0.6)
253+
concurrent-ruby (~> 1.0)
254+
websocket (1.2.10)
255+
websocket-driver (0.7.6)
256+
websocket-extensions (>= 0.1.0)
257+
websocket-extensions (0.1.5)
258+
xpath (3.2.0)
259+
nokogiri (~> 1.8)
260+
zeitwerk (2.6.7)
261+
262+
PLATFORMS
263+
x86_64-darwin-20
264+
x86_64-linux
265+
266+
DEPENDENCIES
267+
appraisal
268+
bundler (= 2.4.9)
269+
capybara
270+
codeclimate-test-reporter
271+
coffee-rails
272+
es5-shim-rails (>= 2.0.5)
273+
gem-release
274+
guard
275+
guard-minitest
276+
jbuilder
277+
listen (~> 3.0.0)
278+
minitest-retry
279+
package_json
280+
pry-byebug
281+
rails (~> 7.0.7, >= 7.0.7.2)
282+
react-rails!
283+
selenium-webdriver
284+
propshaft (~> 1.0.x)
285+
test-unit (~> 2.5)
286+
turbo-rails
287+
288+
BUNDLED WITH
289+
2.4.9

lib/react/server_rendering/bundle_renderer.rb

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require "react/server_rendering/manifest_container"
55
require "react/server_rendering/yaml_manifest_container"
66
require "react/server_rendering/separate_server_bundle_container"
7+
require "react/server_rendering/propshaft_container"
78

89
module React
910
module ServerRendering
@@ -103,6 +104,7 @@ def assets_precompiled?
103104
def asset_container_class
104105
return self.class.asset_container_class if self.class.asset_container_class.present?
105106
return SeparateServerBundleContainer if SeparateServerBundleContainer.compatible?
107+
return PropshaftContainer if PropshaftContainer.compatible?
106108

107109
return EnvironmentContainer unless assets_precompiled?
108110

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
module React
4+
module ServerRendering
5+
# Return asset contents by getting them from a Propshaft::Assembly instance.
6+
class PropshaftContainer
7+
class << self
8+
def assembly
9+
::Rails.application.assets
10+
end
11+
12+
def compatible?
13+
!!defined?(Propshaft) && assembly.is_a?(Propshaft::Assembly)
14+
end
15+
end
16+
17+
def find_asset(path)
18+
self.class.assembly.load_path.find(path).content.force_encoding("utf-8")
19+
end
20+
end
21+
end
22+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
require "open-uri"
5+
6+
class PropshaftContainerTest < ActiveSupport::TestCase
7+
PropshaftHelpers.when_propshaft_available do
8+
def test_it_loads_js_from_the_propshaft_container
9+
container = React::ServerRendering::PropshaftContainer.new
10+
11+
assert_not_empty container.find_asset("server_rendering.js")
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)