Skip to content

Commit af79d57

Browse files
committed
Fix RuboCop violations after rebase
1 parent 8137965 commit af79d57

File tree

96 files changed

+4504
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+4504
-100
lines changed

lib/react_on_rails/prerender_error.rb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ def to_error_context
4747

4848
private
4949

50+
# rubocop:disable Metrics/AbcSize
5051
def calc_message(component_name, console_messages, err, js_code, props)
5152
header = Rainbow("❌ React on Rails Server Rendering Error").red.bright
5253
message = +"#{header}\n\n"
53-
54+
5455
message << Rainbow("Component: #{component_name}").yellow << "\n\n"
55-
56+
5657
if err
5758
message << Rainbow("Error Details:").red.bright << "\n"
5859
message << <<~MSG
@@ -69,11 +70,11 @@ def calc_message(component_name, console_messages, err, js_code, props)
6970
else
7071
backtrace = nil
7172
end
72-
73+
7374
# Add props information
7475
message << Rainbow("Props:").blue.bright << "\n"
7576
message << "#{Utils.smart_trim(props, MAX_ERROR_SNIPPET_TO_LOG)}\n\n"
76-
77+
7778
# Add code snippet
7879
message << Rainbow("JavaScript Code:").blue.bright << "\n"
7980
message << "#{Utils.smart_trim(js_code, MAX_ERROR_SNIPPET_TO_LOG)}\n\n"
@@ -86,39 +87,41 @@ def calc_message(component_name, console_messages, err, js_code, props)
8687
# Add actionable suggestions
8788
message << Rainbow("💡 Troubleshooting Steps:").yellow.bright << "\n"
8889
message << build_troubleshooting_suggestions(component_name, err, console_messages)
89-
90+
9091
# Add help and support information
9192
message << "\n#{Utils.default_troubleshooting_section}\n"
9293

9394
[backtrace, message]
9495
end
95-
96+
# rubocop:enable Metrics/AbcSize
97+
98+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
9699
def build_troubleshooting_suggestions(component_name, err, console_messages)
97100
suggestions = []
98-
101+
99102
# Check for common error patterns
100103
if err&.message&.include?("window is not defined") || console_messages&.include?("window is not defined")
101104
suggestions << <<~SUGGESTION
102105
1. Browser API used on server - wrap with client-side check:
103106
#{Rainbow("if (typeof window !== 'undefined') { ... }").cyan}
104107
SUGGESTION
105108
end
106-
109+
107110
if err&.message&.include?("document is not defined") || console_messages&.include?("document is not defined")
108111
suggestions << <<~SUGGESTION
109112
1. DOM API used on server - use React refs or useEffect:
110-
#{Rainbow("useEffect(() => { /* DOM operations here */ }, [])").cyan}
113+
#{Rainbow('useEffect(() => { /* DOM operations here */ }, [])').cyan}
111114
SUGGESTION
112115
end
113-
116+
114117
if err&.message&.include?("Cannot read") || err&.message&.include?("undefined")
115118
suggestions << <<~SUGGESTION
116119
1. Check for null/undefined values in props
117120
2. Add default props or use optional chaining:
118121
#{Rainbow("props.data?.value || 'default'").cyan}
119122
SUGGESTION
120123
end
121-
124+
122125
if err&.message&.include?("Hydration") || console_messages&.include?("Hydration")
123126
suggestions << <<~SUGGESTION
124127
1. Server and client render mismatch - ensure consistent:
@@ -127,20 +130,21 @@ def build_troubleshooting_suggestions(component_name, err, console_messages)
127130
- User agent checks (avoid or use props)
128131
SUGGESTION
129132
end
130-
133+
131134
# Generic suggestions
132135
suggestions << <<~SUGGESTION
133136
• Temporarily disable SSR to isolate the issue:
134-
#{Rainbow("prerender: false").cyan} in your view helper
137+
#{Rainbow('prerender: false').cyan} in your view helper
135138
• Check server logs for detailed errors:
136-
#{Rainbow("tail -f log/development.log").cyan}
139+
#{Rainbow('tail -f log/development.log').cyan}
137140
• Verify component registration:
138141
#{Rainbow("ReactOnRails.register({ #{component_name}: #{component_name} })").cyan}
139142
• Ensure server bundle is up to date:
140-
#{Rainbow("bin/shakapacker").cyan} or #{Rainbow("yarn run build:server").cyan}
143+
#{Rainbow('bin/shakapacker').cyan} or #{Rainbow('yarn run build:server').cyan}
141144
SUGGESTION
142-
145+
143146
suggestions.join("\n")
144147
end
148+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
145149
end
146150
end

0 commit comments

Comments
 (0)