Skip to content

Commit

Permalink
put ROR scripts after the first rendered chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
AbanoubGhadban committed Jun 18, 2024
1 parent 151c33b commit 69ce6fd
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions lib/react_on_rails/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,6 @@ def generated_components_pack_path(react_component_name)
"#{ReactOnRails::WebpackerUtils.webpacker_source_entry_path}/generated/#{react_component_name}.js"
end

def get_content_tag_options_html_tag(render_options)

end

def build_react_component_result_for_server_rendered_string(
server_rendered_html: required("server_rendered_html"),
component_specification_tag: required("component_specification_tag"),
Expand Down Expand Up @@ -380,24 +376,24 @@ def build_react_component_result_for_server_streamed_content(
component_specification_tag: required("component_specification_tag"),
render_options: required("render_options")
)
content_tag_options_html_tag = render_options.html_options[:tag] || 'div'
# The component_specification_tag is appended to the first chunk
# We need to pass it early with the first chunk because it's needed in hydration
# We need to make sure that client can hydrate the app early even before all components are streamed
is_first_chunk = true

rendered_html_stream = rendered_html_stream.prepend { rails_context_if_not_already_rendered }
.prepend { "<#{content_tag_options_html_tag} id=\"#{render_options.dom_id}\">" }
.transform(&:html_safe)

rendered_html_stream = rendered_html_stream.transform do |chunk|
is_first_chunk = false
if is_first_chunk
return "#{chunk}\n#{component_specification_tag}"
is_first_chunk = false
next "#{chunk}\n#{component_specification_tag}"
end
chunk
end
.append { "</#{content_tag_options_html_tag}>" }

content_tag_options_html_tag = render_options.html_options[:tag] || "div"
rendered_html_stream = rendered_html_stream.prepend { rails_context_if_not_already_rendered }
.prepend { "<#{content_tag_options_html_tag} id=\"#{render_options.dom_id}\">" }
.transform(&:html_safe)

rendered_html_stream.append { "</#{content_tag_options_html_tag}>" }
.append { component_specification_tag }
# TODO: handle console logs
end
Expand Down

0 comments on commit 69ce6fd

Please sign in to comment.