Skip to content

Commit 69ce6fd

Browse files
put ROR scripts after the first rendered chunk
1 parent 151c33b commit 69ce6fd

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

lib/react_on_rails/helper.rb

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,6 @@ def generated_components_pack_path(react_component_name)
344344
"#{ReactOnRails::WebpackerUtils.webpacker_source_entry_path}/generated/#{react_component_name}.js"
345345
end
346346

347-
def get_content_tag_options_html_tag(render_options)
348-
349-
end
350-
351347
def build_react_component_result_for_server_rendered_string(
352348
server_rendered_html: required("server_rendered_html"),
353349
component_specification_tag: required("component_specification_tag"),
@@ -380,24 +376,24 @@ def build_react_component_result_for_server_streamed_content(
380376
component_specification_tag: required("component_specification_tag"),
381377
render_options: required("render_options")
382378
)
383-
content_tag_options_html_tag = render_options.html_options[:tag] || 'div'
384379
# The component_specification_tag is appended to the first chunk
385380
# We need to pass it early with the first chunk because it's needed in hydration
386381
# We need to make sure that client can hydrate the app early even before all components are streamed
387382
is_first_chunk = true
388-
389-
rendered_html_stream = rendered_html_stream.prepend { rails_context_if_not_already_rendered }
390-
.prepend { "<#{content_tag_options_html_tag} id=\"#{render_options.dom_id}\">" }
391-
.transform(&:html_safe)
392-
393383
rendered_html_stream = rendered_html_stream.transform do |chunk|
394-
is_first_chunk = false
395384
if is_first_chunk
396-
return "#{chunk}\n#{component_specification_tag}"
385+
is_first_chunk = false
386+
next "#{chunk}\n#{component_specification_tag}"
397387
end
398388
chunk
399389
end
400-
.append { "</#{content_tag_options_html_tag}>" }
390+
391+
content_tag_options_html_tag = render_options.html_options[:tag] || "div"
392+
rendered_html_stream = rendered_html_stream.prepend { rails_context_if_not_already_rendered }
393+
.prepend { "<#{content_tag_options_html_tag} id=\"#{render_options.dom_id}\">" }
394+
.transform(&:html_safe)
395+
396+
rendered_html_stream.append { "</#{content_tag_options_html_tag}>" }
401397
.append { component_specification_tag }
402398
# TODO: handle console logs
403399
end

0 commit comments

Comments
 (0)