Class: ReactOnRails::ReactComponent::RenderOptions
- Inherits:
-
Object
- Object
- ReactOnRails::ReactComponent::RenderOptions
- Includes:
- Utils::Required
- Defined in:
- lib/react_on_rails/react_component/render_options.rb
Constant Summary collapse
- NO_PROPS =
{}.freeze
Instance Attribute Summary collapse
-
#react_component_name ⇒ Object
readonly
Returns the value of attribute react_component_name.
-
#render_request_id ⇒ Object
readonly
Returns the value of attribute render_request_id.
-
#request_digest ⇒ Object
Returns the value of attribute request_digest.
Class Method Summary collapse
Instance Method Summary collapse
- #auto_load_bundle ⇒ Object
- #client_props ⇒ Object
- #dom_id ⇒ Object
- #force_load ⇒ Object
- #html_options ⇒ Object
- #html_streaming? ⇒ Boolean
-
#initialize(react_component_name: required("react_component_name"), options: required("options")) ⇒ RenderOptions
constructor
TODO: remove the required for named params.
- #internal_option(key) ⇒ Object
- #logging_on_server ⇒ Object
- #prerender ⇒ Object
- #props ⇒ Object
- #raise_non_shell_server_rendering_errors ⇒ Object
- #raise_on_prerender_error ⇒ Object
- #random_dom_id ⇒ Object
- #random_dom_id? ⇒ Boolean
- #render_mode ⇒ Object
- #replay_console ⇒ Object
- #rsc_payload_streaming? ⇒ Boolean
- #set_option(key, value) ⇒ Object
- #store_dependencies ⇒ Object
- #streaming? ⇒ Boolean
- #throw_js_errors ⇒ Object
- #to_s ⇒ Object
- #trace ⇒ Object
Methods included from Utils::Required
Constructor Details
#initialize(react_component_name: required("react_component_name"), options: required("options")) ⇒ RenderOptions
TODO: remove the required for named params
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 15 def initialize(react_component_name: required("react_component_name"), options: required("options")) @react_component_name = react_component_name.camelize @options = # The render_request_id serves as a unique identifier for each render request. # We cannot rely solely on dom_id, as it should be unique for each component on the page, # but the server can render the same page multiple times concurrently for different users. # Therefore, we need an additional unique identifier that can be used both on the client and server. # This ID can also be used to associate specific data with a particular rendered component # on either the server or client. # This ID is only present if RSC support is enabled because it's only used in that case. @render_request_id = self.class.generate_request_id if ReactOnRails::Utils.rsc_support_enabled? end |
Instance Attribute Details
#react_component_name ⇒ Object (readonly)
Returns the value of attribute react_component_name.
28 29 30 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 28 def react_component_name @react_component_name end |
#render_request_id ⇒ Object (readonly)
Returns the value of attribute render_request_id.
28 29 30 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 28 def render_request_id @render_request_id end |
#request_digest ⇒ Object
Returns the value of attribute request_digest.
10 11 12 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 10 def request_digest @request_digest end |
Class Method Details
.generate_request_id ⇒ Object
150 151 152 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 150 def self.generate_request_id SecureRandom.uuid end |
Instance Method Details
#auto_load_bundle ⇒ Object
82 83 84 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 82 def auto_load_bundle retrieve_configuration_value_for(:auto_load_bundle) end |
#client_props ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 38 def client_props props_extension = ReactOnRails.configuration.rendering_props_extension if props_extension.present? if props_extension.respond_to?(:adjust_props_for_client_side_hydration) return props_extension.adjust_props_for_client_side_hydration(react_component_name, props.clone) end raise ReactOnRails::Error, "ReactOnRails: your rendering_props_extension module is missing the " \ "required adjust_props_for_client_side_hydration method & can not be used" end props end |
#dom_id ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 56 def dom_id @dom_id ||= .fetch(:id) do if random_dom_id generate_unique_dom_id else base_dom_id end end end |
#force_load ⇒ Object
106 107 108 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 106 def force_load retrieve_configuration_value_for(:force_load) end |
#html_options ⇒ Object
74 75 76 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 74 def [:html_options].to_h end |
#html_streaming? ⇒ Boolean
141 142 143 144 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 141 def html_streaming? # Returns true if the component should be rendered incrementally render_mode == :html_streaming end |
#internal_option(key) ⇒ Object
114 115 116 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 114 def internal_option(key) [key] end |
#logging_on_server ⇒ Object
102 103 104 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 102 def logging_on_server retrieve_configuration_value_for(:logging_on_server) end |
#prerender ⇒ Object
78 79 80 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 78 def prerender retrieve_configuration_value_for(:prerender) end |
#props ⇒ Object
34 35 36 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 34 def props .fetch(:props) { NO_PROPS } end |
#raise_non_shell_server_rendering_errors ⇒ Object
98 99 100 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 98 def raise_non_shell_server_rendering_errors retrieve_react_on_rails_pro_config_value_for(:raise_non_shell_server_rendering_errors) end |
#raise_on_prerender_error ⇒ Object
94 95 96 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 94 def raise_on_prerender_error retrieve_configuration_value_for(:raise_on_prerender_error) end |
#random_dom_id ⇒ Object
52 53 54 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 52 def random_dom_id retrieve_configuration_value_for(:random_dom_id) end |
#random_dom_id? ⇒ Boolean
66 67 68 69 70 71 72 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 66 def random_dom_id? return false if [:id] return false unless random_dom_id true end |
#render_mode ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 122 def render_mode # Determines the React rendering strategy: # - :sync: Synchronous SSR using renderToString (blocking and rendering in one shot) # - :html_streaming: Progressive SSR using renderToPipeableStream (non-blocking and rendering incrementally) # - :rsc_payload_streaming: Server Components serialized in React flight format # (non-blocking and rendering incrementally). .fetch(:render_mode, :sync) end |
#replay_console ⇒ Object
90 91 92 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 90 def replay_console retrieve_configuration_value_for(:replay_console) end |
#rsc_payload_streaming? ⇒ Boolean
136 137 138 139 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 136 def rsc_payload_streaming? # Returns true if the component should be rendered as a React Server Component render_mode == :rsc_payload_streaming end |
#set_option(key, value) ⇒ Object
118 119 120 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 118 def set_option(key, value) [key] = value end |
#store_dependencies ⇒ Object
146 147 148 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 146 def store_dependencies [:store_dependencies] end |
#streaming? ⇒ Boolean
131 132 133 134 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 131 def streaming? # Returns true if the component should be rendered incrementally %i[html_streaming rsc_payload_streaming].include?(render_mode) end |
#throw_js_errors ⇒ Object
30 31 32 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 30 def throw_js_errors .fetch(:throw_js_errors, false) end |
#to_s ⇒ Object
110 111 112 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 110 def to_s "{ react_component_name = #{react_component_name}, options = #{}, request_digest = #{request_digest}" end |
#trace ⇒ Object
86 87 88 |
# File 'lib/react_on_rails/react_component/render_options.rb', line 86 def trace retrieve_configuration_value_for(:trace) end |