Skip to content

Commit 64107f3

Browse files
authored
Merge pull request rails#41874 from jacobherrington/error-page-css-and-a11y-improvements
Error page CSS and a11y improvements
2 parents f7e19de + 126cd61 commit 64107f3

13 files changed

+61
-45
lines changed

actionpack/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove inline styles and address basic accessibilty issues on rescue templates.
2+
3+
*Jacob Herrington*
4+
15
* Add support for 'private, no-store' Cache-Control headers.
26

37
Previously, 'no-store' was exclusive; no other directives could be specified.

actionpack/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<b>Did you mean?</b>
1212
<ul>
1313
<% corrections.each do |correction| %>
14-
<li style="list-style-type: none"><%= h correction %></li>
14+
<li class="correction"><%= h correction %></li>
1515
<% end %>
1616
</ul>
1717
<% end %>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
<h2 style="margin-top: 30px">Request</h2>
1+
<h2 class="request-heading">Request</h2>
22
<% if params_valid? %>
33
<p><b>Parameters</b>:</p> <pre><%= debug_params(@request.filtered_parameters) %></pre>
44
<% end %>
55

66
<div class="details">
77
<div class="summary"><a href="#" onclick="return toggleSessionDump()">Toggle session dump</a></div>
8-
<div id="session_dump" style="display:none"><pre><%= debug_hash @request.session %></pre></div>
8+
<div id="session_dump" class="hidden"><pre><%= debug_hash @request.session %></pre></div>
99
</div>
1010

1111
<div class="details">
1212
<div class="summary"><a href="#" onclick="return toggleEnvDump()">Toggle env dump</a></div>
13-
<div id="env_dump" style="display:none"><pre><%= debug_hash @request.env.slice(*@request.class::ENV_METHODS) %></pre></div>
13+
<div id="env_dump" class="hidden"><pre><%= debug_hash @request.env.slice(*@request.class::ENV_METHODS) %></pre></div>
1414
</div>
1515

16-
<h2 style="margin-top: 30px">Response</h2>
16+
<h2 class="response-heading">Response</h2>
1717
<p><b>Headers</b>:</p> <pre><%= debug_headers(defined?(@response) ? @response.headers : {}) %></pre>

actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<% traces.each do |name, trace| %>
1616
<div id="<%= "#{name.gsub(/\s/, '-')}-#{error_index}" %>" style="display: <%= (name == trace_to_show) ? 'block' : 'none' %>;">
17-
<code style="font-size: 11px;">
17+
<code class="traces">
1818
<% trace.each do |frame| %>
1919
<a class="trace-frames trace-frames-<%= error_index %>" data-exception-object-id="<%= frame[:exception_object_id] %>" data-frame-id="<%= frame[:id] %>" href="#">
2020
<%= frame[:trace] %>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<header>
22
<h1>Blocked host: <%= @host %></h1>
33
</header>
4-
<div id="container">
4+
<main role="main" id="container">
55
<h2>To allow requests to <%= @host %>, add the following to your environment configuration:</h2>
66
<pre>config.hosts &lt;&lt; "<%= @host %>"</pre>
7-
</div>
7+
</main>

actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</h1>
88
</header>
99

10-
<div id="container">
10+
<main role="main" id="container">
1111
<%= render "rescues/message_and_suggestions", exception: @exception %>
1212
<%= render "rescues/actions", exception: @exception, request: @request %>
1313

@@ -20,16 +20,16 @@
2020

2121
<% @exception_wrapper.wrapped_causes.each.with_index(1) do |wrapper, index| %>
2222
<div class="details">
23-
<a class="summary" href="#" style="color: #F0F0F0; text-decoration: none; background: #C52F24; border-bottom: none;" onclick="return toggle(<%= wrapper.exception.object_id %>)">
23+
<a class="summary" href="#" onclick="return toggle(<%= wrapper.exception.object_id %>)">
2424
<%= wrapper.exception.class.name %>: <%= h wrapper.exception.message %>
2525
</a>
2626
</div>
2727

28-
<div id="<%= wrapper.exception.object_id %>" style="display: none;">
28+
<div id="<%= wrapper.exception.object_id %>" class="hidden">
2929
<%= render "rescues/source", source_extracts: wrapper.source_extracts, show_source_idx: wrapper.source_to_show_id, error_index: index %>
3030
<%= render "rescues/trace", traces: wrapper.traces, trace_to_show: wrapper.trace_to_show, error_index: index %>
3131
</div>
3232
<% end %>
3333

3434
<%= render template: "rescues/_request_and_response" %>
35-
</div>
35+
</main>

actionpack/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<header>
1+
<header role="banner">
22
<h1>
33
<%= @exception.class.to_s %>
44
<% if @request.parameters['controller'] %>
@@ -7,7 +7,7 @@
77
</h1>
88
</header>
99

10-
<div id="container">
10+
<main role="main" id="container">
1111
<h2>
1212
<%= h @exception.message %>
1313
<% if defined?(ActiveStorage) && @exception.message.match?(%r{#{ActiveStorage::Blob.table_name}|#{ActiveStorage::Attachment.table_name}}) %>
@@ -21,4 +21,4 @@
2121
<%= render "rescues/source", source_extracts: @source_extracts, show_source_idx: @show_source_idx %>
2222
<%= render "rescues/trace", traces: @traces, trace_to_show: @trace_to_show %>
2323
<%= render template: "rescues/_request_and_response" %>
24-
</div>
24+
</main>

actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@
4949
line-height: 25px;
5050
}
5151

52+
code.traces {
53+
font-size: 11px;
54+
}
55+
56+
.response-heading, .request-heading {
57+
margin-top: 30px;
58+
}
59+
5260
.exception-message {
5361
padding: 8px 0;
5462
}
5563

56-
.exception-message .message{
64+
.exception-message .message {
5765
margin-bottom: 8px;
5866
line-height: 25px;
5967
font-size: 1.5em;
@@ -75,6 +83,13 @@
7583
display: block;
7684
}
7785

86+
a.summary {
87+
color: #F0F0F0;
88+
text-decoration: none;
89+
background: #C52F24;
90+
border-bottom: none;
91+
}
92+
7893
.details pre {
7994
margin: 5px;
8095
border: none;
@@ -114,7 +129,7 @@
114129

115130
.source .data .line_numbers {
116131
background-color: #ECECEC;
117-
color: #AAA;
132+
color: #555;
118133
padding: 1em .5em;
119134
border-right: 1px solid #DDD;
120135
text-align: right;
@@ -143,6 +158,10 @@
143158
display: none;
144159
}
145160

161+
.correction {
162+
list-style-type: none;
163+
}
164+
146165
input[type="submit"] {
147166
color: white;
148167
background-color: #C00;
@@ -165,27 +184,22 @@
165184
transform: translateY(1px)
166185
}
167186

168-
169187
a { color: #980905; }
170188
a:visited { color: #666; }
171189
a.trace-frames {
172190
color: #666;
173191
overflow-wrap: break-word;
174192
}
175-
a:hover { color: #C00; }
176-
a.trace-frames.selected { color: #C00 }
193+
a:hover, a.trace-frames.selected { color: #C00; }
194+
a.summary:hover { color: #FFF; }
177195

178196
@media (prefers-color-scheme: dark) {
179197
body {
180198
background-color: #222;
181199
color: #ECECEC;
182200
}
183201

184-
.details {
185-
border-color: #666;
186-
}
187-
188-
.summary {
202+
.details, .summary {
189203
border-color: #666;
190204
}
191205

@@ -220,17 +234,15 @@
220234

221235
a { color: #C00; }
222236
a.trace-frames { color: #999; }
223-
a:hover { color: #E9382B; }
224-
a.trace-frames.selected { color: #E9382B; }
237+
a:hover, a.trace-frames.selected { color: #E9382B; }
225238
}
226239

227240
<%= yield :style %>
228241
</style>
229242

230243
<script>
231244
var toggle = function(id) {
232-
var s = document.getElementById(id).style;
233-
s.display = s.display == 'none' ? 'block' : 'none';
245+
document.getElementById(id).classList.toggle('hidden');
234246
return false;
235247
}
236248
var show = function(id) {
@@ -249,7 +261,7 @@
249261
</head>
250262
<body>
251263

252-
<%= yield %>
264+
<%= yield %>
253265

254266
</body>
255267
</html>

actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<header>
1+
<header role="banner">
22
<h1>No template for interactive request</h1>
33
</header>
44

5-
<div id="container">
5+
<main id="container">
66
<h2><%= h @exception.message %></h2>
77

88
<p class="summary">
@@ -16,4 +16,4 @@
1616
since we expect an HTML template
1717
to be rendered for such requests. If that's the case, carry on.
1818
</p>
19-
</div>
19+
</main>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<header>
1+
<header role="banner">
22
<h1>Template is missing</h1>
33
</header>
44

5-
<div id="container">
5+
<main role="main" id="container">
66
<h2><%= h @exception.message %></h2>
77

88
<%= render "rescues/source", source_extracts: @source_extracts, show_source_idx: @show_source_idx %>
99
<%= render "rescues/trace", traces: @traces, trace_to_show: @trace_to_show %>
1010
<%= render template: "rescues/_request_and_response" %>
11-
</div>
11+
</main>

0 commit comments

Comments
 (0)