Skip to content

Commit

Permalink
fix review/rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
theforestvn88 committed May 22, 2024
1 parent d2e0e27 commit 7bfde72
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/react_on_rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/react_on_rails/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,15 @@ 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, %(
ReactOnRails.reactOnRailsComponentLoaded('#{render_options.dom_id}');
).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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %>
<% end %>
Original file line number Diff line number Diff line change
@@ -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 %>
<% end %>
4 changes: 2 additions & 2 deletions spec/dummy/spec/helpers/react_on_rails_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ class PlainReactOnRailsHelper
it { is_expected.to include '<div id="App-react-component-0"></div>' }
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 }
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/spec/system/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down

0 comments on commit 7bfde72

Please sign in to comment.