react_on_rails 16.2.0.beta.4 → 16.2.0.beta.8
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/CHANGELOG.md +27 -8
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.development_dependencies +0 -1
- data/Gemfile.lock +1 -9
- data/bin/ci-rerun-failures +39 -16
- data/bin/ci-run-failed-specs +1 -1
- data/bin/ci-switch-config +8 -2
- data/bin/lefthook/ruby-autofix +2 -1
- data/knip.ts +35 -9
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt +32 -52
- data/lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml +5 -1
- data/lib/react_on_rails/dev/server_manager.rb +11 -4
- data/lib/react_on_rails/doctor.rb +245 -0
- data/lib/react_on_rails/helper.rb +9 -0
- data/lib/react_on_rails/version.rb +1 -1
- data/react_on_rails_pro/CHANGELOG.md +7 -0
- data/react_on_rails_pro/CONTRIBUTING.md +2 -13
- data/react_on_rails_pro/Gemfile.lock +21 -3
- data/react_on_rails_pro/docs/code-splitting-loadable-components.md +1 -1
- data/react_on_rails_pro/docs/contributors-info/releasing.md +2 -2
- data/react_on_rails_pro/docs/installation.md +106 -104
- data/react_on_rails_pro/docs/node-renderer/basics.md +3 -3
- data/react_on_rails_pro/docs/node-renderer/error-reporting-and-tracing.md +8 -8
- data/react_on_rails_pro/docs/node-renderer/js-configuration.md +1 -1
- data/react_on_rails_pro/docs/updating.md +209 -15
- data/react_on_rails_pro/lib/react_on_rails_pro/concerns/stream.rb +58 -4
- data/react_on_rails_pro/lib/react_on_rails_pro/configuration.rb +17 -3
- data/react_on_rails_pro/lib/react_on_rails_pro/license_public_key.rb +9 -9
- data/react_on_rails_pro/lib/react_on_rails_pro/request.rb +41 -25
- data/react_on_rails_pro/lib/react_on_rails_pro/stream_request.rb +27 -7
- data/react_on_rails_pro/lib/react_on_rails_pro/utils.rb +3 -3
- data/react_on_rails_pro/lib/react_on_rails_pro/version.rb +1 -1
- data/react_on_rails_pro/package-scripts.yml +1 -1
- data/react_on_rails_pro/package.json +5 -8
- data/react_on_rails_pro/packages/node-renderer/src/integrations/api.ts +1 -1
- data/react_on_rails_pro/rakelib/public_key_management.rake +6 -5
- data/react_on_rails_pro/react_on_rails_pro.gemspec +1 -0
- data/react_on_rails_pro/spec/dummy/Gemfile.lock +20 -3
- data/react_on_rails_pro/spec/dummy/app/controllers/pages_controller.rb +3 -3
- data/react_on_rails_pro/spec/dummy/bin/dev +4 -8
- data/react_on_rails_pro/spec/dummy/client/node-renderer.js +3 -3
- data/react_on_rails_pro/spec/dummy/config/environments/production.rb +1 -1
- data/react_on_rails_pro/spec/dummy/config/initializers/react_on_rails.rb +28 -12
- data/react_on_rails_pro/spec/dummy/config.ru +1 -1
- data/react_on_rails_pro/spec/dummy/package.json +2 -2
- data/react_on_rails_pro/spec/dummy/spec/helpers/react_on_rails_pro_helper_spec.rb +40 -11
- data/react_on_rails_pro/spec/dummy/spec/rails_helper.rb +1 -1
- data/react_on_rails_pro/spec/dummy/spec/requests/renderer_console_logging_spec.rb +5 -5
- data/react_on_rails_pro/spec/dummy/spec/system/integration_spec.rb +20 -14
- data/react_on_rails_pro/spec/dummy/spec/system/renderer_integration_spec.rb +3 -3
- data/react_on_rails_pro/spec/dummy/yarn.lock +4 -4
- data/react_on_rails_pro/spec/execjs-compatible-dummy/config/environments/production.rb +1 -1
- data/react_on_rails_pro/spec/execjs-compatible-dummy/config/initializers/react_on_rails.rb +16 -43
- data/react_on_rails_pro/spec/react_on_rails_pro/assets_precompile_spec.rb +15 -18
- data/react_on_rails_pro/spec/react_on_rails_pro/cache_spec.rb +1 -1
- data/react_on_rails_pro/spec/react_on_rails_pro/configuration_spec.rb +5 -3
- data/react_on_rails_pro/spec/react_on_rails_pro/license_validator_spec.rb +27 -12
- data/react_on_rails_pro/spec/react_on_rails_pro/request_spec.rb +0 -27
- data/react_on_rails_pro/spec/react_on_rails_pro/spec_helper.rb +1 -1
- data/react_on_rails_pro/spec/react_on_rails_pro/stream_decorator_spec.rb +89 -0
- data/react_on_rails_pro/spec/react_on_rails_pro/stream_spec.rb +144 -0
- data/react_on_rails_pro/spec/react_on_rails_pro/support/caching.rb +1 -1
- data/react_on_rails_pro/spec/react_on_rails_pro/support/mock_block_helper.rb +4 -2
- metadata +2 -3
- data/react_on_rails_pro/spec/dummy/client/app/ror-auto-load-components/TestingStreamableComponent.jsx +0 -15
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# ⚠️ TEST CONFIGURATION - Do not copy directly for production apps
|
|
4
|
+
# This is the Pro dummy app configuration used for testing React on Rails Pro features.
|
|
5
|
+
# See docs/api-reference/configuration.md for production configuration guidance.
|
|
6
|
+
|
|
7
|
+
# Advanced: Custom rendering extension to add values to railsContext
|
|
4
8
|
module RenderingExtension
|
|
5
|
-
# Return a Hash that contains custom values from the view context that will get passed to
|
|
6
|
-
# all calls to react_component and redux_store for rendering
|
|
7
9
|
def self.custom_context(view_context)
|
|
8
10
|
if view_context.controller.is_a?(ActionMailer::Base)
|
|
9
11
|
{}
|
|
@@ -15,6 +17,7 @@ module RenderingExtension
|
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
|
|
20
|
+
# Advanced: Custom props extension for client-side hydration
|
|
18
21
|
module RenderingPropsExtension
|
|
19
22
|
def self.adjust_props_for_client_side_hydration(_component_name, props)
|
|
20
23
|
if props.instance_of?(Hash)
|
|
@@ -26,19 +29,32 @@ module RenderingPropsExtension
|
|
|
26
29
|
end
|
|
27
30
|
|
|
28
31
|
ReactOnRails.configure do |config|
|
|
32
|
+
################################################################################
|
|
33
|
+
# Essential Configuration
|
|
34
|
+
################################################################################
|
|
29
35
|
config.server_bundle_js_file = "server-bundle.js"
|
|
36
|
+
config.components_subdirectory = "ror-auto-load-components"
|
|
37
|
+
config.auto_load_bundle = true
|
|
38
|
+
|
|
39
|
+
################################################################################
|
|
40
|
+
# Pro Feature Testing: Server Bundle Security
|
|
41
|
+
################################################################################
|
|
42
|
+
# Testing private server bundle enforcement (recommended for production)
|
|
43
|
+
config.enforce_private_server_bundles = true
|
|
44
|
+
config.server_bundle_output_path = "ssr-generated"
|
|
45
|
+
|
|
46
|
+
################################################################################
|
|
47
|
+
# Test-specific Advanced Configuration
|
|
48
|
+
################################################################################
|
|
49
|
+
# Testing with fixed DOM IDs for easier test assertions
|
|
30
50
|
config.random_dom_id = false # default is true
|
|
31
51
|
|
|
32
|
-
#
|
|
33
|
-
# config.build_test_command = "yarn run build:test"
|
|
34
|
-
# config.webpack_generated_files = %w[server-bundle.js manifest.json]
|
|
52
|
+
# Testing advanced rendering customization
|
|
35
53
|
config.rendering_extension = RenderingExtension
|
|
36
|
-
|
|
37
54
|
config.rendering_props_extension = RenderingPropsExtension
|
|
38
55
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
config.
|
|
43
|
-
config.server_bundle_output_path = "ssr-generated"
|
|
56
|
+
# NOTE: build_test_command and webpack_generated_files are commented out
|
|
57
|
+
# because we've set test.compile to true in shakapacker.yml
|
|
58
|
+
# config.build_test_command = "yarn run build:test"
|
|
59
|
+
# config.webpack_generated_files = %w[server-bundle.js manifest.json]
|
|
44
60
|
end
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@loadable/server": "^5.16.2",
|
|
18
18
|
"@loadable/webpack-plugin": "^5.15.2",
|
|
19
19
|
"@sentry/node": "^7.120.0",
|
|
20
|
-
"
|
|
20
|
+
"react-on-rails-pro-node-renderer": "link:.yalc/react-on-rails-pro-node-renderer",
|
|
21
21
|
"@shakacode/use-ssr-computation.macro": "^1.2.4",
|
|
22
22
|
"@shakacode/use-ssr-computation.runtime": "^2.0.0",
|
|
23
23
|
"@webpack-cli/serve": "^1.6.0",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"test": "yarn run build:test && yarn run lint && rspec",
|
|
99
99
|
"lint": "cd ../.. && nps lint",
|
|
100
100
|
"e2e-test": "playwright test",
|
|
101
|
-
"preinstall": "yarn run link-source && yalc add --link react-on-rails-pro && cd .yalc/react-on-rails-pro && yalc add --link react-on-rails && cd ../.. && yalc add --link
|
|
101
|
+
"preinstall": "yarn run link-source && yalc add --link react-on-rails-pro && cd .yalc/react-on-rails-pro && yalc add --link react-on-rails && cd ../.. && yalc add --link react-on-rails-pro-node-renderer",
|
|
102
102
|
"link-source": "cd ../../.. && yarn && yarn run yalc:publish && cd react_on_rails_pro && yarn && yalc publish",
|
|
103
103
|
"postinstall": "test -f post-yarn-install.local && ./post-yarn-install.local || true",
|
|
104
104
|
"build:test": "rm -rf public/webpack/test && rm -rf ssr-generated && RAILS_ENV=test NODE_ENV=test bin/shakapacker",
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "async"
|
|
4
|
+
require "async/queue"
|
|
3
5
|
require "rails_helper"
|
|
4
6
|
require "support/script_tag_utils"
|
|
5
7
|
|
|
@@ -327,10 +329,10 @@ describe ReactOnRailsProHelper do
|
|
|
327
329
|
HTML
|
|
328
330
|
end
|
|
329
331
|
|
|
332
|
+
# mock_chunks can be an Async::Queue or an Array
|
|
330
333
|
def mock_request_and_response(mock_chunks = chunks, count: 1)
|
|
331
334
|
# Reset connection instance variables to ensure clean state for tests
|
|
332
335
|
ReactOnRailsPro::Request.instance_variable_set(:@connection, nil)
|
|
333
|
-
ReactOnRailsPro::Request.instance_variable_set(:@connection_without_retries, nil)
|
|
334
336
|
original_httpx_plugin = HTTPX.method(:plugin)
|
|
335
337
|
allow(HTTPX).to receive(:plugin) do |*args|
|
|
336
338
|
original_httpx_plugin.call(:mock_stream).plugin(*args)
|
|
@@ -340,9 +342,19 @@ describe ReactOnRailsProHelper do
|
|
|
340
342
|
chunks_read.clear
|
|
341
343
|
mock_streaming_response(%r{http://localhost:3800/bundles/[a-f0-9]{32}-test/render/[a-f0-9]{32}}, 200,
|
|
342
344
|
count: count) do |yielder|
|
|
343
|
-
mock_chunks.
|
|
344
|
-
|
|
345
|
-
|
|
345
|
+
if mock_chunks.is_a?(Async::Queue)
|
|
346
|
+
loop do
|
|
347
|
+
chunk = mock_chunks.dequeue
|
|
348
|
+
break if chunk.nil?
|
|
349
|
+
|
|
350
|
+
chunks_read << chunk
|
|
351
|
+
yielder.call("#{chunk.to_json}\n")
|
|
352
|
+
end
|
|
353
|
+
else
|
|
354
|
+
mock_chunks.each do |chunk|
|
|
355
|
+
chunks_read << chunk
|
|
356
|
+
yielder.call("#{chunk.to_json}\n")
|
|
357
|
+
end
|
|
346
358
|
end
|
|
347
359
|
end
|
|
348
360
|
end
|
|
@@ -429,18 +441,35 @@ describe ReactOnRailsProHelper do
|
|
|
429
441
|
|
|
430
442
|
allow(mocked_stream).to receive(:write) do |chunk|
|
|
431
443
|
written_chunks << chunk
|
|
432
|
-
# Ensures that any chunk received is written immediately to the stream
|
|
433
|
-
expect(written_chunks.count).to eq(chunks_read.count) # rubocop:disable RSpec/ExpectInHook
|
|
434
444
|
end
|
|
435
445
|
allow(mocked_stream).to receive(:close)
|
|
436
446
|
mocked_response = instance_double(ActionDispatch::Response)
|
|
437
447
|
allow(mocked_response).to receive(:stream).and_return(mocked_stream)
|
|
438
448
|
allow(self).to receive(:response).and_return(mocked_response)
|
|
439
|
-
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
def execute_stream_view_containing_react_components
|
|
452
|
+
queue = Async::Queue.new
|
|
453
|
+
mock_request_and_response(queue)
|
|
454
|
+
|
|
455
|
+
Sync do |parent|
|
|
456
|
+
parent.async { stream_view_containing_react_components(template: template_path) }
|
|
457
|
+
|
|
458
|
+
chunks_to_write = chunks.dup
|
|
459
|
+
while (chunk = chunks_to_write.shift)
|
|
460
|
+
queue.enqueue(chunk)
|
|
461
|
+
sleep 0.05
|
|
462
|
+
|
|
463
|
+
# Ensures that any chunk received is written immediately to the stream
|
|
464
|
+
expect(written_chunks.count).to eq(chunks_read.count)
|
|
465
|
+
end
|
|
466
|
+
queue.close
|
|
467
|
+
sleep 0.05
|
|
468
|
+
end
|
|
440
469
|
end
|
|
441
470
|
|
|
442
471
|
it "writes the chunk to stream as soon as it is received" do
|
|
443
|
-
|
|
472
|
+
execute_stream_view_containing_react_components
|
|
444
473
|
expect(self).to have_received(:render_to_string).once.with(template: template_path)
|
|
445
474
|
expect(chunks_read.count).to eq(chunks.count)
|
|
446
475
|
expect(written_chunks.count).to eq(chunks.count)
|
|
@@ -449,7 +478,7 @@ describe ReactOnRailsProHelper do
|
|
|
449
478
|
end
|
|
450
479
|
|
|
451
480
|
it "prepends the rails context to the first chunk only" do
|
|
452
|
-
|
|
481
|
+
execute_stream_view_containing_react_components
|
|
453
482
|
initial_result = written_chunks.first
|
|
454
483
|
expect(initial_result).to script_tag_be_included(rails_context_tag)
|
|
455
484
|
|
|
@@ -465,7 +494,7 @@ describe ReactOnRailsProHelper do
|
|
|
465
494
|
end
|
|
466
495
|
|
|
467
496
|
it "prepends the component specification tag to the first chunk only" do
|
|
468
|
-
|
|
497
|
+
execute_stream_view_containing_react_components
|
|
469
498
|
initial_result = written_chunks.first
|
|
470
499
|
expect(initial_result).to script_tag_be_included(react_component_specification_tag)
|
|
471
500
|
|
|
@@ -476,7 +505,7 @@ describe ReactOnRailsProHelper do
|
|
|
476
505
|
end
|
|
477
506
|
|
|
478
507
|
it "renders the rails view content in the first chunk" do
|
|
479
|
-
|
|
508
|
+
execute_stream_view_containing_react_components
|
|
480
509
|
initial_result = written_chunks.first
|
|
481
510
|
expect(initial_result).to include("<h1>Header Rendered In View</h1>")
|
|
482
511
|
written_chunks[1..].each do |chunk|
|
|
@@ -53,7 +53,7 @@ RSpec.configure do |config|
|
|
|
53
53
|
|
|
54
54
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
|
55
55
|
# For React on Rails Pro, using loadable-stats.json
|
|
56
|
-
config.fixture_paths = ["#{
|
|
56
|
+
config.fixture_paths = ["#{Rails.root}/spec/fixtures"]
|
|
57
57
|
|
|
58
58
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
|
59
59
|
# examples within a transaction, remove the following line or assign false
|
|
@@ -15,11 +15,11 @@ describe "Console logging from server" do
|
|
|
15
15
|
html_nodes = Nokogiri::HTML(response.body)
|
|
16
16
|
expected = <<~JS
|
|
17
17
|
console.log.apply(console, ["[SERVER] RENDERED ReduxSharedStoreApp to dom node with id: ReduxSharedStoreApp-react-component-0"]);
|
|
18
|
-
console.log.apply(console, ["[SERVER] This is a script
|
|
19
|
-
console.log.apply(console, ["[SERVER] Script2
|
|
20
|
-
console.log.apply(console, ["[SERVER] Script3
|
|
21
|
-
console.log.apply(console, ["[SERVER] Script4
|
|
22
|
-
console.log.apply(console, ["[SERVER] Script5
|
|
18
|
+
console.log.apply(console, ["[SERVER] This is a script:\\"</div>\\"(/script> <script>alert('WTF1')(/script>"]);
|
|
19
|
+
console.log.apply(console, ["[SERVER] Script2:\\"</div>\\"(/script xx> <script>alert('WTF2')(/script xx>"]);
|
|
20
|
+
console.log.apply(console, ["[SERVER] Script3:\\"</div>\\"(/script xx> <script>alert('WTF3')(/script xx>"]);
|
|
21
|
+
console.log.apply(console, ["[SERVER] Script4\\"</div>\\"(/script <script>alert('WTF4')(/script>"]);
|
|
22
|
+
console.log.apply(console, ["[SERVER] Script5:\\"</div>\\"(/script> <script>alert('WTF5')(/script>"]);
|
|
23
23
|
console.log.apply(console, ["[SERVER] railsContext.serverSide is ","true"]);
|
|
24
24
|
JS
|
|
25
25
|
|
|
@@ -11,7 +11,7 @@ def change_text_expect_dom_selector(dom_selector, expect_no_change: false)
|
|
|
11
11
|
find("input").set new_text
|
|
12
12
|
within("h3") do
|
|
13
13
|
if expect_no_change
|
|
14
|
-
expect(subject).
|
|
14
|
+
expect(subject).to have_no_content new_text
|
|
15
15
|
else
|
|
16
16
|
expect(subject).to have_content new_text
|
|
17
17
|
end
|
|
@@ -110,7 +110,7 @@ describe "Turbolinks across pages", :js do
|
|
|
110
110
|
it "changes name in message according to input" do
|
|
111
111
|
visit "/client_side_hello_world"
|
|
112
112
|
change_text_expect_dom_selector("#HelloWorld-react-component-0")
|
|
113
|
-
|
|
113
|
+
click_on "Hello World Component Server Rendered, with extra options"
|
|
114
114
|
change_text_expect_dom_selector("#my-hello-world-id")
|
|
115
115
|
end
|
|
116
116
|
end
|
|
@@ -174,19 +174,19 @@ describe "React Router", :js do
|
|
|
174
174
|
|
|
175
175
|
before do
|
|
176
176
|
visit "/"
|
|
177
|
-
|
|
177
|
+
click_on "React Router"
|
|
178
178
|
end
|
|
179
179
|
|
|
180
180
|
context "when rendering /react_router" do
|
|
181
181
|
it { is_expected.to have_text("Woohoo, we can use react-router here!") }
|
|
182
182
|
|
|
183
183
|
it "clicking links correctly renders other pages" do
|
|
184
|
-
|
|
184
|
+
click_on "Router First Page"
|
|
185
185
|
expect(page).to have_current_path("/react_router/first_page")
|
|
186
186
|
first_page_header_text = page.find(:css, "h2#first-page").text
|
|
187
187
|
expect(first_page_header_text).to eq("React Router First Page")
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
click_on "Router Second Page"
|
|
190
190
|
expect(page).to have_current_path("/react_router/second_page")
|
|
191
191
|
second_page_header_text = page.find(:css, "h2#second-page").text
|
|
192
192
|
expect(second_page_header_text).to eq("React Router Second Page")
|
|
@@ -239,12 +239,12 @@ describe "async render function returns component", :js do
|
|
|
239
239
|
end
|
|
240
240
|
end
|
|
241
241
|
|
|
242
|
-
describe "Manual client hydration", :js
|
|
242
|
+
describe "Manual client hydration", :js do
|
|
243
243
|
before { visit "/xhr_refresh" }
|
|
244
244
|
|
|
245
245
|
it "HelloWorldRehydratable onChange should trigger" do
|
|
246
246
|
within("form") do
|
|
247
|
-
|
|
247
|
+
click_on "refresh"
|
|
248
248
|
end
|
|
249
249
|
within("#HelloWorldRehydratable-react-component-1") do
|
|
250
250
|
find("input").set "Should update"
|
|
@@ -396,20 +396,20 @@ shared_examples "streamed component tests" do |path, selector|
|
|
|
396
396
|
|
|
397
397
|
it "hydrates the component" do
|
|
398
398
|
visit path
|
|
399
|
-
expect(page.html).to match(/client-bundle[
|
|
399
|
+
expect(page.html).to match(/client-bundle[^"]*.js/)
|
|
400
400
|
change_text_expect_dom_selector(selector)
|
|
401
401
|
end
|
|
402
402
|
|
|
403
403
|
it "renders the page completely on server and displays content on client even without JavaScript" do
|
|
404
404
|
# Don't add client-bundle.js to the page to ensure that the app is not hydrated
|
|
405
405
|
visit "#{path}?skip_js_packs=true"
|
|
406
|
-
expect(page.html).not_to match(/client-bundle[
|
|
406
|
+
expect(page.html).not_to match(/client-bundle[^"]*.js/)
|
|
407
407
|
# Ensure that the component state is not updated
|
|
408
408
|
change_text_expect_dom_selector(selector, expect_no_change: true)
|
|
409
409
|
|
|
410
|
-
expect(page).
|
|
411
|
-
expect(page).
|
|
412
|
-
expect(page).
|
|
410
|
+
expect(page).to have_no_text "Loading branch1"
|
|
411
|
+
expect(page).to have_no_text "Loading branch2"
|
|
412
|
+
expect(page).to have_no_text(/Loading branch1 at level \d+/)
|
|
413
413
|
expect(page).to have_text(/branch1 \(level \d+\)/, count: 5)
|
|
414
414
|
end
|
|
415
415
|
|
|
@@ -417,8 +417,8 @@ shared_examples "streamed component tests" do |path, selector|
|
|
|
417
417
|
# visit waits for the page to load, so we ensure that the page is loaded before checking the hydration status
|
|
418
418
|
visit "#{path}?skip_js_packs=true"
|
|
419
419
|
expect(page).to have_text "HydrationStatus: Streaming server render"
|
|
420
|
-
expect(page).
|
|
421
|
-
expect(page).
|
|
420
|
+
expect(page).to have_no_text "HydrationStatus: Hydrated"
|
|
421
|
+
expect(page).to have_no_text "HydrationStatus: Page loaded"
|
|
422
422
|
end
|
|
423
423
|
end
|
|
424
424
|
|
|
@@ -430,4 +430,10 @@ end
|
|
|
430
430
|
describe "React Router Sixth Page", :js do
|
|
431
431
|
it_behaves_like "streamed component tests", "/server_router/streaming-server-component",
|
|
432
432
|
"#ServerComponentRouter-react-component-0"
|
|
433
|
+
|
|
434
|
+
# Skip the test that fails without JavaScript - being addressed in another PR
|
|
435
|
+
it "renders the page completely on server and displays content on client even without JavaScript", # rubocop:disable RSpec/NoExpectationExample
|
|
436
|
+
skip: "Being addressed in another PR" do
|
|
437
|
+
# This test is overridden to skip it
|
|
438
|
+
end
|
|
433
439
|
end
|
|
@@ -9,14 +9,14 @@ describe "Shared Redux store example", :server_rendering do
|
|
|
9
9
|
|
|
10
10
|
context "with enabled JS", :js do
|
|
11
11
|
it "Has correct heading and text inside the text input" do
|
|
12
|
-
expect(page).to
|
|
13
|
-
expect(page).to
|
|
12
|
+
expect(page).to have_css("h3", text: /\ARedux Hello, Mr. Server Side Rendering!\z/)
|
|
13
|
+
expect(page).to have_css("input[type='text'][value='Mr. Server Side Rendering']")
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "updates header in reaction to text input changes" do
|
|
17
17
|
new_value = "new value"
|
|
18
18
|
all("input[type='text']")[0].set(new_value)
|
|
19
|
-
expect(page).to
|
|
19
|
+
expect(page).to have_css("h3", text: /\ARedux Hello, #{new_value}!\z/)
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
end
|
|
@@ -1228,10 +1228,6 @@
|
|
|
1228
1228
|
dependencies:
|
|
1229
1229
|
"@sentry/types" "7.120.0"
|
|
1230
1230
|
|
|
1231
|
-
"@shakacode-tools/react-on-rails-pro-node-renderer@link:.yalc/@shakacode-tools/react-on-rails-pro-node-renderer":
|
|
1232
|
-
version "0.0.0"
|
|
1233
|
-
uid ""
|
|
1234
|
-
|
|
1235
1231
|
"@shakacode/use-ssr-computation.macro@^1.2.4":
|
|
1236
1232
|
version "1.2.4"
|
|
1237
1233
|
resolved "https://registry.yarnpkg.com/@shakacode/use-ssr-computation.macro/-/use-ssr-computation.macro-1.2.4.tgz#b247d683e3133126dbdb42060c26e1c34a8b625d"
|
|
@@ -5461,6 +5457,10 @@ react-is@^16.12.0, react-is@^16.13.1, react-is@^16.7.0:
|
|
|
5461
5457
|
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
|
|
5462
5458
|
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
|
|
5463
5459
|
|
|
5460
|
+
"react-on-rails-pro-node-renderer@link:.yalc/react-on-rails-pro-node-renderer":
|
|
5461
|
+
version "0.0.0"
|
|
5462
|
+
uid ""
|
|
5463
|
+
|
|
5464
5464
|
"react-on-rails-pro@link:.yalc/react-on-rails-pro":
|
|
5465
5465
|
version "0.0.0"
|
|
5466
5466
|
uid ""
|
|
@@ -55,7 +55,7 @@ Rails.application.configure do
|
|
|
55
55
|
|
|
56
56
|
# Log to STDOUT by default
|
|
57
57
|
config.logger = ActiveSupport::Logger.new($stdout)
|
|
58
|
-
.tap { |logger| logger.formatter =
|
|
58
|
+
.tap { |logger| logger.formatter = Logger::Formatter.new }
|
|
59
59
|
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
|
|
60
60
|
|
|
61
61
|
# Prepend all log lines with the following tags.
|
|
@@ -1,58 +1,31 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
# for
|
|
3
|
+
# ⚠️ TEST CONFIGURATION - Do not copy directly for production apps
|
|
4
|
+
# This is the ExecJS-compatible dummy app for testing legacy webpacker compatibility.
|
|
5
|
+
# See docs/api-reference/configuration.md for production configuration guidance.
|
|
5
6
|
|
|
6
7
|
ReactOnRails.configure do |config|
|
|
7
|
-
# This configures the script to run to build the production assets by webpack. Set this to nil
|
|
8
|
-
# if you don't want react_on_rails building this file for you.
|
|
9
|
-
# If nil, then the standard shakacode/webpacker assets:precompile will run
|
|
10
|
-
# config.build_production_command = nil
|
|
11
|
-
|
|
12
|
-
################################################################################
|
|
13
8
|
################################################################################
|
|
14
|
-
#
|
|
15
|
-
# Below options are used with the use of this test helper:
|
|
16
|
-
# ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
|
9
|
+
# Essential Configuration
|
|
17
10
|
################################################################################
|
|
11
|
+
# Configure server bundle for server-side rendering
|
|
12
|
+
config.server_bundle_js_file = "server-bundle.js"
|
|
18
13
|
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
# ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
|
22
|
-
#
|
|
23
|
-
# with rspec then this controls what yarn command is run
|
|
24
|
-
# to automatically refresh your webpack assets on every test run.
|
|
25
|
-
#
|
|
26
|
-
# Alternately, you can remove the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`
|
|
27
|
-
# and set the config/webpacker.yml option for test to true.
|
|
14
|
+
# Test configuration
|
|
28
15
|
config.build_test_command = "RAILS_ENV=test bin/webpacker"
|
|
29
16
|
|
|
30
17
|
################################################################################
|
|
18
|
+
# File System Based Component Registry (Optional - Disabled for this test)
|
|
31
19
|
################################################################################
|
|
32
|
-
#
|
|
33
|
-
|
|
34
|
-
#
|
|
35
|
-
|
|
36
|
-
# Note, there is only one server bundle, unlike JavaScript where you want to minimize the size
|
|
37
|
-
# of the JS sent to the client. For the server rendering, React on Rails creates a pool of
|
|
38
|
-
# JavaScript execution instances which should handle any component requested.
|
|
39
|
-
#
|
|
40
|
-
# While you may configure this to be the same as your client bundle file, this file is typically
|
|
41
|
-
# different. You should have ONE server bundle which can create all of your server rendered
|
|
42
|
-
# React components.
|
|
43
|
-
#
|
|
44
|
-
config.server_bundle_js_file = "server-bundle.js"
|
|
20
|
+
# Uncomment to enable automatic component registration:
|
|
21
|
+
# config.components_subdirectory = "ror_components"
|
|
22
|
+
# config.auto_load_bundle = true
|
|
23
|
+
config.auto_load_bundle = false
|
|
45
24
|
|
|
46
25
|
################################################################################
|
|
26
|
+
# Advanced Configuration
|
|
47
27
|
################################################################################
|
|
48
|
-
#
|
|
49
|
-
|
|
50
|
-
#
|
|
51
|
-
# for use in the Rails views. The default is nil, you can enable the feature by updating it in the next line.
|
|
52
|
-
# config.components_subdirectory = "ror_components"
|
|
53
|
-
#
|
|
54
|
-
# For automated component registry, `render_component` view helper method tries to load bundle for component from
|
|
55
|
-
# generated directory. default is false, you can pass option at the time of individual usage or update the default
|
|
56
|
-
# in the following line
|
|
57
|
-
config.auto_load_bundle = false
|
|
28
|
+
# Most options have sensible defaults. For advanced configuration including
|
|
29
|
+
# component loading strategies, server bundle security, and more, see:
|
|
30
|
+
# https://github.com/shakacode/react_on_rails/blob/master/docs/api-reference/configuration.md
|
|
58
31
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "
|
|
3
|
+
require_relative "spec_helper"
|
|
4
4
|
require_relative "../../lib/react_on_rails_pro/assets_precompile"
|
|
5
5
|
|
|
6
6
|
describe ReactOnRailsPro::AssetsPrecompile do
|
|
@@ -46,8 +46,6 @@ describe ReactOnRailsPro::AssetsPrecompile do
|
|
|
46
46
|
|
|
47
47
|
ror_pro_config = instance_double(ReactOnRailsPro::Configuration)
|
|
48
48
|
|
|
49
|
-
allow(ror_pro_config).to receive(:dependency_globs).and_return([expected_parameters.last])
|
|
50
|
-
|
|
51
49
|
adapter = Module.new do
|
|
52
50
|
def self.cache_keys
|
|
53
51
|
%w[a b]
|
|
@@ -58,7 +56,8 @@ describe ReactOnRailsPro::AssetsPrecompile do
|
|
|
58
56
|
end
|
|
59
57
|
end
|
|
60
58
|
|
|
61
|
-
allow(ror_pro_config).to
|
|
59
|
+
allow(ror_pro_config).to receive_messages(dependency_globs: [expected_parameters.last],
|
|
60
|
+
remote_bundle_cache_adapter: adapter)
|
|
62
61
|
|
|
63
62
|
stub_const("ReactOnRailsPro::VERSION", "2.2.0")
|
|
64
63
|
|
|
@@ -136,11 +135,10 @@ describe ReactOnRailsPro::AssetsPrecompile do
|
|
|
136
135
|
it "calls build_bundles & cache_bundles if cached bundles can't be fetched" do
|
|
137
136
|
instance = described_class.instance
|
|
138
137
|
|
|
139
|
-
allow(instance).to receive(:fetch_and_unzip_cached_bundles).and_return(false)
|
|
140
138
|
expect(instance).to receive(:fetch_and_unzip_cached_bundles).once
|
|
141
|
-
allow(instance).to receive(:build_bundles).and_return(nil)
|
|
142
139
|
expect(instance).to receive(:build_bundles).once
|
|
143
|
-
allow(instance).to
|
|
140
|
+
allow(instance).to receive_messages(fetch_and_unzip_cached_bundles: false, build_bundles: nil,
|
|
141
|
+
cache_bundles: nil)
|
|
144
142
|
expect(instance).to receive(:cache_bundles).once
|
|
145
143
|
|
|
146
144
|
instance.build_or_fetch_bundles
|
|
@@ -179,9 +177,9 @@ describe ReactOnRailsPro::AssetsPrecompile do
|
|
|
179
177
|
unique_variable = { unique_key: "a unique value" }
|
|
180
178
|
|
|
181
179
|
instance = described_class.instance
|
|
182
|
-
allow(instance).to
|
|
183
|
-
|
|
184
|
-
|
|
180
|
+
allow(instance).to receive_messages(remote_bundle_cache_adapter: adapter_double,
|
|
181
|
+
zipped_bundles_filename: unique_variable,
|
|
182
|
+
zipped_bundles_filepath: "zipped_bundles_filepath")
|
|
185
183
|
|
|
186
184
|
allow(File).to receive(:binwrite).and_return(true)
|
|
187
185
|
expect(File).to receive(:binwrite).once
|
|
@@ -197,8 +195,7 @@ describe ReactOnRailsPro::AssetsPrecompile do
|
|
|
197
195
|
allow(File).to receive(:exist?).and_return(false)
|
|
198
196
|
|
|
199
197
|
instance = described_class.instance
|
|
200
|
-
allow(instance).to
|
|
201
|
-
allow(instance).to receive(:zipped_bundles_filepath).and_return("a")
|
|
198
|
+
allow(instance).to receive_messages(fetch_bundles: false, zipped_bundles_filepath: "a")
|
|
202
199
|
|
|
203
200
|
expect(instance.fetch_and_unzip_cached_bundles).to be(false)
|
|
204
201
|
end
|
|
@@ -256,10 +253,10 @@ describe ReactOnRailsPro::AssetsPrecompile do
|
|
|
256
253
|
zipped_bundles_filepath = Pathname.new(Dir.tmpdir).join("foobar")
|
|
257
254
|
|
|
258
255
|
instance = described_class.instance
|
|
259
|
-
allow(instance).to
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
256
|
+
allow(instance).to receive_messages(remote_bundle_cache_adapter: adapter_double,
|
|
257
|
+
zipped_bundles_filename: "zipped_bundles_filename",
|
|
258
|
+
zipped_bundles_filepath: zipped_bundles_filepath,
|
|
259
|
+
remove_extra_files_cache_dir: nil)
|
|
263
260
|
|
|
264
261
|
expect(instance.cache_bundles).to be_truthy
|
|
265
262
|
|
|
@@ -289,8 +286,8 @@ describe ReactOnRailsPro::AssetsPrecompile do
|
|
|
289
286
|
|
|
290
287
|
instance = described_class.instance
|
|
291
288
|
|
|
292
|
-
allow(instance).to
|
|
293
|
-
|
|
289
|
+
allow(instance).to receive_messages(remote_bundle_cache_adapter: adapter,
|
|
290
|
+
extra_files_path: Pathname.new(Dir.pwd).join("extra_files_cache_dir"))
|
|
294
291
|
copied_gemfile_path = Pathname.new(Dir.pwd).join("extra_files_cache_dir", "Gemfile")
|
|
295
292
|
copied_assets_precompile_path = Pathname.new(Dir.pwd).join("extra_files_cache_dir",
|
|
296
293
|
"lib---react_on_rails_pro---assets_precompile.rb")
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "spec_helper"
|
|
4
4
|
|
|
5
|
-
module ReactOnRailsPro
|
|
5
|
+
module ReactOnRailsPro # rubocop:disable Metrics/ModuleLength
|
|
6
6
|
RSpec.describe Configuration do
|
|
7
7
|
after do
|
|
8
8
|
ReactOnRailsPro.instance_variable_set(:@configuration, nil)
|
|
@@ -205,7 +205,8 @@ module ReactOnRailsPro
|
|
|
205
205
|
|
|
206
206
|
expect(ReactOnRailsPro.configuration.rsc_bundle_js_file).to eq("rsc-bundle.js")
|
|
207
207
|
expect(ReactOnRailsPro.configuration.react_client_manifest_file).to eq("react-client-manifest.json")
|
|
208
|
-
expect(ReactOnRailsPro.configuration.react_server_client_manifest_file)
|
|
208
|
+
expect(ReactOnRailsPro.configuration.react_server_client_manifest_file)
|
|
209
|
+
.to eq("react-server-client-manifest.json")
|
|
209
210
|
end
|
|
210
211
|
|
|
211
212
|
it "allows setting rsc_bundle_js_file" do
|
|
@@ -229,7 +230,8 @@ module ReactOnRailsPro
|
|
|
229
230
|
config.react_server_client_manifest_file = "custom-server-client-manifest.json"
|
|
230
231
|
end
|
|
231
232
|
|
|
232
|
-
expect(ReactOnRailsPro.configuration.react_server_client_manifest_file)
|
|
233
|
+
expect(ReactOnRailsPro.configuration.react_server_client_manifest_file)
|
|
234
|
+
.to eq("custom-server-client-manifest.json")
|
|
233
235
|
end
|
|
234
236
|
|
|
235
237
|
it "allows nil values for RSC configuration options" do
|