From 7bfde7281aa6d1d8d5830d1401d056bb87b308e2 Mon Sep 17 00:00:00 2001 From: theforestvn88 Date: Wed, 22 May 2024 16:03:29 +0700 Subject: [PATCH] fix review/rubocop --- lib/react_on_rails/configuration.rb | 2 ++ lib/react_on_rails/helper.rb | 4 ++-- .../app/views/pages/turbo_frame_tag_hello_world.html.erb | 2 +- .../pages/turbo_stream_send_hello_world.turbo_stream.erb | 2 +- spec/dummy/spec/helpers/react_on_rails_helper_spec.rb | 4 ++-- spec/dummy/spec/system/integration_spec.rb | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/react_on_rails/configuration.rb b/lib/react_on_rails/configuration.rb index 5700319cda..6097d2db6b 100644 --- a/lib/react_on_rails/configuration.rb +++ b/lib/react_on_rails/configuration.rb @@ -40,6 +40,7 @@ def self.configuration components_subdirectory: nil, make_generated_server_bundle_the_entrypoint: false, defer_generated_component_packs: true, + # forces the loading of React components force_load: false ) end @@ -108,6 +109,7 @@ def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender self.auto_load_bundle = auto_load_bundle self.make_generated_server_bundle_the_entrypoint = make_generated_server_bundle_the_entrypoint self.defer_generated_component_packs = defer_generated_component_packs + self.force_load = force_load end # rubocop:enable Metrics/AbcSize diff --git a/lib/react_on_rails/helper.rb b/lib/react_on_rails/helper.rb index 345453b2f3..011be95754 100644 --- a/lib/react_on_rails/helper.rb +++ b/lib/react_on_rails/helper.rb @@ -440,7 +440,7 @@ def internal_react_component(react_component_name, options = {}) "data-component-name" => render_options.react_component_name, "data-trace" => (render_options.trace ? true : nil), "data-dom-id" => render_options.dom_id) - + if render_options.force_load component_specification_tag.concat( content_tag(:script, %( @@ -448,7 +448,7 @@ def internal_react_component(react_component_name, options = {}) ).html_safe) ) end - + load_pack_for_generated_component(react_component_name, render_options) # Create the HTML rendering part result = server_rendered_react_component(render_options) diff --git a/spec/dummy/app/views/pages/turbo_frame_tag_hello_world.html.erb b/spec/dummy/app/views/pages/turbo_frame_tag_hello_world.html.erb index 34d6889629..df7747e19f 100644 --- a/spec/dummy/app/views/pages/turbo_frame_tag_hello_world.html.erb +++ b/spec/dummy/app/views/pages/turbo_frame_tag_hello_world.html.erb @@ -1,3 +1,3 @@ <%= turbo_frame_tag 'hello-turbo-stream' do %> <%= button_to "send me hello-turbo-stream component", turbo_stream_send_hello_world_path %> -<% end %> \ No newline at end of file +<% end %> diff --git a/spec/dummy/app/views/pages/turbo_stream_send_hello_world.turbo_stream.erb b/spec/dummy/app/views/pages/turbo_stream_send_hello_world.turbo_stream.erb index 2fb020add1..93e5b75c61 100644 --- a/spec/dummy/app/views/pages/turbo_stream_send_hello_world.turbo_stream.erb +++ b/spec/dummy/app/views/pages/turbo_stream_send_hello_world.turbo_stream.erb @@ -1,3 +1,3 @@ <%= turbo_stream.update 'hello-turbo-stream' do %> <%= react_component("HelloTurboStream", props: @app_props_hello_from_turbo_stream, force_load: true) %> -<% end %> \ No newline at end of file +<% end %> diff --git a/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb b/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb index 8993f51e01..f3b9e2aecb 100644 --- a/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb +++ b/spec/dummy/spec/helpers/react_on_rails_helper_spec.rb @@ -289,14 +289,14 @@ class PlainReactOnRailsHelper it { is_expected.to include '
' } end - context "force load" do + describe "'force_load' tag option" do let(:force_load_script) do %( ReactOnRails.reactOnRailsComponentLoaded('App-react-component-0'); ).html_safe end - context "with 'force_load' tag option" do + context "with 'force_load' == true" do subject { react_component("App", force_load: true) } it { is_expected.to include force_load_script } diff --git a/spec/dummy/spec/system/integration_spec.rb b/spec/dummy/spec/system/integration_spec.rb index 142b9a9cbc..788fd04aae 100644 --- a/spec/dummy/spec/system/integration_spec.rb +++ b/spec/dummy/spec/system/integration_spec.rb @@ -100,7 +100,7 @@ def finished_all_ajax_requests? describe "TurboStream send react component", :js do subject { page } - it "should force load hello-world component immediately" do + it "force load hello-world component immediately" do visit "/turbo_frame_tag_hello_world" click_on "send me hello-turbo-stream component" expect(page).to have_text "Hello, Mrs. Client Side Rendering From Turbo Stream!"