Class: Rhales::HydrationConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/rhales/configuration.rb

Overview

Hydration-specific configuration settings

Controls how hydration scripts are injected into HTML templates. Supports multiple injection strategies for different performance characteristics:

Traditional Strategies

  • :late (default) - injects before </body> tag (safest, backwards compatible)
  • :early - injects before detected mount points for improved performance
  • :earliest - injects in HTML head section for maximum performance
  • :link - basic link reference to API endpoint
  • :prefetch - browser prefetch for future page loads
  • :preload - high priority preload for current page
  • :modulepreload - ES module preloading
  • :lazy - intersection observer-based lazy loading

Constant Summary collapse

VALID_STRATEGIES =
[:late, :early, :earliest, :link, :prefetch, :preload, :modulepreload, :lazy].freeze
[:link, :prefetch, :preload, :modulepreload, :lazy].freeze
DEFAULT_API_CACHE_TTL =

5 minutes

300

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHydrationConfiguration

Returns a new instance of HydrationConfiguration.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rhales/configuration.rb', line 63

def initialize
  # Traditional strategy settings
  @injection_strategy = :late
  @mount_point_selectors = ['#app', '#root', '[data-rsfc-mount]', '[data-mount]']
  @fallback_to_late = true
  @fallback_when_unsafe = true
  @disable_early_for_templates = []

  # API endpoint settings
  @api_endpoint_enabled = false
  @api_endpoint_path = '/api/hydration'

  # Link tag settings
  @link_crossorigin = true

  # Module export settings
  @module_export_enabled = false

  # Lazy loading settings
  @lazy_mount_selector = '#app'

  # Reflection system settings
  @reflection_enabled = true

  # Caching settings
  @api_cache_enabled = false
  @api_cache_ttl = DEFAULT_API_CACHE_TTL

  # CORS settings
  @cors_enabled = false
  @cors_origin = '*'
end

Instance Attribute Details

#api_cache_enabledObject

Caching configuration for API endpoints



58
59
60
# File 'lib/rhales/configuration.rb', line 58

def api_cache_enabled
  @api_cache_enabled
end

#api_cache_ttlObject

Caching configuration for API endpoints



58
59
60
# File 'lib/rhales/configuration.rb', line 58

def api_cache_ttl
  @api_cache_ttl
end

#api_endpoint_enabledObject

API endpoint configuration for link-based strategies



43
44
45
# File 'lib/rhales/configuration.rb', line 43

def api_endpoint_enabled
  @api_endpoint_enabled
end

#api_endpoint_pathObject

API endpoint configuration for link-based strategies



43
44
45
# File 'lib/rhales/configuration.rb', line 43

def api_endpoint_path
  @api_endpoint_path
end

#cors_enabledObject

CORS configuration for API endpoints



61
62
63
# File 'lib/rhales/configuration.rb', line 61

def cors_enabled
  @cors_enabled
end

#cors_originObject

CORS configuration for API endpoints



61
62
63
# File 'lib/rhales/configuration.rb', line 61

def cors_origin
  @cors_origin
end

#disable_early_for_templatesObject

Disable early injection for specific templates (array of template names)



40
41
42
# File 'lib/rhales/configuration.rb', line 40

def disable_early_for_templates
  @disable_early_for_templates
end

#fallback_to_lateObject

Whether to fallback to late injection when no mount points detected



34
35
36
# File 'lib/rhales/configuration.rb', line 34

def fallback_to_late
  @fallback_to_late
end

#fallback_when_unsafeObject

Whether to fallback to late injection when early injection is unsafe



37
38
39
# File 'lib/rhales/configuration.rb', line 37

def fallback_when_unsafe
  @fallback_when_unsafe
end

#injection_strategyObject

Injection strategy - one of VALID_STRATEGIES



28
29
30
# File 'lib/rhales/configuration.rb', line 28

def injection_strategy
  @injection_strategy
end

#lazy_mount_selectorObject

Lazy loading configuration



52
53
54
# File 'lib/rhales/configuration.rb', line 52

def lazy_mount_selector
  @lazy_mount_selector
end

Link tag configuration



46
47
48
# File 'lib/rhales/configuration.rb', line 46

def link_crossorigin
  @link_crossorigin
end

#module_export_enabledObject

Module export configuration for :modulepreload strategy



49
50
51
# File 'lib/rhales/configuration.rb', line 49

def module_export_enabled
  @module_export_enabled
end

#mount_point_selectorsObject

Array of CSS selectors to detect frontend mount points



31
32
33
# File 'lib/rhales/configuration.rb', line 31

def mount_point_selectors
  @mount_point_selectors
end

#reflection_enabledObject

Data attribute reflection system



55
56
57
# File 'lib/rhales/configuration.rb', line 55

def reflection_enabled
  @reflection_enabled
end

Instance Method Details

#api_endpoints_required?Boolean

Check if API endpoints should be enabled

Returns:

  • (Boolean)


110
111
112
# File 'lib/rhales/configuration.rb', line 110

def api_endpoints_required?
  link_based_strategy? || @api_endpoint_enabled
end

Check if current strategy is link-based

Returns:

  • (Boolean)


105
106
107
# File 'lib/rhales/configuration.rb', line 105

def link_based_strategy?
  LINK_BASED_STRATEGIES.include?(@injection_strategy)
end