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.



61
62
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
# File 'lib/rhales/configuration.rb', line 61

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



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

def api_cache_enabled
  @api_cache_enabled
end

#api_cache_ttlObject

Caching configuration for API endpoints



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

def api_cache_ttl
  @api_cache_ttl
end

#api_endpoint_enabledObject

API endpoint configuration for link-based strategies



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

def api_endpoint_enabled
  @api_endpoint_enabled
end

#api_endpoint_pathObject

API endpoint configuration for link-based strategies



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

def api_endpoint_path
  @api_endpoint_path
end

#cors_enabledObject

CORS configuration for API endpoints



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

def cors_enabled
  @cors_enabled
end

#cors_originObject

CORS configuration for API endpoints



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

def cors_origin
  @cors_origin
end

#disable_early_for_templatesObject

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



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

def disable_early_for_templates
  @disable_early_for_templates
end

#fallback_to_lateObject

Whether to fallback to late injection when no mount points detected



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

def fallback_to_late
  @fallback_to_late
end

#fallback_when_unsafeObject

Whether to fallback to late injection when early injection is unsafe



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

def fallback_when_unsafe
  @fallback_when_unsafe
end

#injection_strategyObject

Injection strategy - one of VALID_STRATEGIES



26
27
28
# File 'lib/rhales/configuration.rb', line 26

def injection_strategy
  @injection_strategy
end

#lazy_mount_selectorObject

Lazy loading configuration



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

def lazy_mount_selector
  @lazy_mount_selector
end

Link tag configuration



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

def link_crossorigin
  @link_crossorigin
end

#module_export_enabledObject

Module export configuration for :modulepreload strategy



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

def module_export_enabled
  @module_export_enabled
end

#mount_point_selectorsObject

Array of CSS selectors to detect frontend mount points



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

def mount_point_selectors
  @mount_point_selectors
end

#reflection_enabledObject

Data attribute reflection system



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

def reflection_enabled
  @reflection_enabled
end

Instance Method Details

#api_endpoints_required?Boolean

Check if API endpoints should be enabled

Returns:

  • (Boolean)


108
109
110
# File 'lib/rhales/configuration.rb', line 108

def api_endpoints_required?
  link_based_strategy? || @api_endpoint_enabled
end

Check if current strategy is link-based

Returns:

  • (Boolean)


103
104
105
# File 'lib/rhales/configuration.rb', line 103

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