module ReactOnRails::ProHelper

def generate_component_script(render_options)

Handles both immediate hydration (Pro feature) and standard cases.
Generates the complete component specification script tag.
def generate_component_script(render_options)
  # Setup the page_loaded_js, which is the same regardless of prerendering or not!
  # The reason is that React is smart about not doing extra work if the server rendering did its job.
  component_specification_tag = content_tag(:script,
                                            json_safe_and_pretty(render_options.client_props).html_safe,
                                            type: "application/json",
                                            class: "js-react-on-rails-component",
                                            id: "js-react-on-rails-component-#{render_options.dom_id}",
                                            "data-component-name" => render_options.react_component_name,
                                            "data-trace" => (render_options.trace ? true : nil),
                                            "data-dom-id" => render_options.dom_id,
                                            "data-store-dependencies" =>
                                              render_options.store_dependencies&.to_json,
                                            "data-immediate-hydration" =>
                                              (render_options.immediate_hydration ? true : nil))
  # Add immediate invocation script if immediate hydration is enabled
  spec_tag = if render_options.immediate_hydration
               # Escape dom_id for JavaScript context
               escaped_dom_id = escape_javascript(render_options.dom_id)
               immediate_script = content_tag(:script, %(
      typeof ReactOnRails === 'object' && ReactOnRails.reactOnRailsComponentLoaded('#{escaped_dom_id}');
    ).html_safe)
               "#{component_specification_tag}\n#{immediate_script}"
             else
               component_specification_tag
             end
  spec_tag.html_safe
end