Skip to content

Commit 16c9604

Browse files
justin808claude
andcommitted
Fix RBS type accuracy and improve error handling
Type Accuracy Fixes: - Change Configuration#initialize raise_on_prerender_error from bool to bool? to allow nil values (matches actual implementation) - Replace String return types with safe_buffer type alias for methods that return html_safe strings (ActiveSupport::SafeBuffer): - Helper: react_component, react_component_hash, redux_store, redux_store_hydration_data, server_render_js - Controller: redux_store_hydration_data - Private helpers: build_react_component_result_for_server_rendered_string, build_react_component_result_for_server_rendered_hash, prepend_render_rails_context Infrastructure Improvements: - Improve rake task error handling with explicit case statement for nil (handles cases where RBS command is not found) - Add rubocop disable directive for Metrics/BlockLength in rbs.rake The safe_buffer type alias (= String) documents that these methods return html_safe strings while maintaining RBS compatibility without requiring ActiveSupport type definitions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8d83c38 commit 16c9604

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

rakelib/rbs.rake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
# rubocop:disable Metrics/BlockLength
34
namespace :rbs do
45
desc "Validate RBS type signatures"
56
task :validate do
@@ -11,11 +12,15 @@ namespace :rbs do
1112
# Run RBS validate
1213
result = system("bundle exec rbs -I sig validate")
1314

14-
if result
15+
case result
16+
when true
1517
puts "✓ RBS validation passed"
16-
else
18+
when false
1719
puts "✗ RBS validation failed"
1820
exit 1
21+
when nil
22+
puts "✗ RBS command not found or could not be executed"
23+
exit 1
1924
end
2025
end
2126

@@ -30,3 +35,4 @@ namespace :rbs do
3035
puts "\nTotal: #{sig_files.count} files"
3136
end
3237
end
38+
# rubocop:enable Metrics/BlockLength

sig/react_on_rails/configuration.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module ReactOnRails
4747
?logging_on_server: bool?,
4848
?server_renderer_pool_size: Integer?,
4949
?server_renderer_timeout: Integer?,
50-
?raise_on_prerender_error: bool,
50+
?raise_on_prerender_error: bool?,
5151
?skip_display_none: bool?,
5252
?generated_assets_dirs: Array[String]?,
5353
?generated_assets_dir: String?,

sig/react_on_rails/controller.rbs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
module ReactOnRails
22
module Controller
3+
# Type alias for ActiveSupport::SafeBuffer (html_safe strings)
4+
type safe_buffer = String
5+
36
def redux_store: (
47
String store_name,
58
?props: untyped,
69
?immediate_hydration: bool
710
) -> void
811

9-
def redux_store_hydration_data: () -> String
12+
# Returns html_safe string (ActiveSupport::SafeBuffer)
13+
def redux_store_hydration_data: () -> safe_buffer
1014
end
1115
end

sig/react_on_rails/helper.rbs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
module ReactOnRails
22
module Helper
3+
# Type alias for ActiveSupport::SafeBuffer (html_safe strings)
4+
type safe_buffer = String
5+
36
COMPONENT_HTML_KEY: String
47

58
# Main helper methods
9+
# Returns html_safe string (ActiveSupport::SafeBuffer)
610
def react_component: (
711
String component_name,
812
?Hash[Symbol, untyped] options
9-
) ?{ () -> untyped } -> String
13+
) ?{ () -> untyped } -> safe_buffer
1014

15+
# Returns hash with html_safe strings (ActiveSupport::SafeBuffer)
1116
def react_component_hash: (
1217
String component_name,
1318
?Hash[Symbol, untyped] options
14-
) ?{ () -> untyped } -> Hash[String, String]
19+
) ?{ () -> untyped } -> Hash[String, safe_buffer]
1520

21+
# Returns html_safe string (ActiveSupport::SafeBuffer)
1622
def redux_store: (
1723
String store_name,
1824
?Hash[Symbol, untyped] props
19-
) -> String
25+
) -> safe_buffer
2026

21-
def redux_store_hydration_data: () -> String
27+
# Returns html_safe string (ActiveSupport::SafeBuffer)
28+
def redux_store_hydration_data: () -> safe_buffer
2229

30+
# Returns html_safe string (ActiveSupport::SafeBuffer)
2331
def server_render_js: (
2432
String js_expression,
2533
?Hash[Symbol, untyped] options
26-
) -> String
34+
) -> safe_buffer
2735

2836
def sanitized_props_string: (untyped props) -> String
2937

@@ -43,15 +51,15 @@ module ReactOnRails
4351
component_specification_tag: String,
4452
console_script: String,
4553
render_options: Hash[Symbol, untyped]
46-
) -> String
54+
) -> safe_buffer
4755

4856
def build_react_component_result_for_server_rendered_hash: (
4957
server_rendered_html: Hash[String, untyped],
5058
component_specification_tag: String,
5159
console_script: String,
5260
render_options: Hash[Symbol, untyped]
53-
) -> Hash[String, String]
61+
) -> Hash[String, safe_buffer]
5462

55-
def prepend_render_rails_context: (String result) -> String
63+
def prepend_render_rails_context: (String result) -> safe_buffer
5664
end
5765
end

0 commit comments

Comments
 (0)