Skip to content

Commit 0681e24

Browse files
bvaughngaearon
authored andcommitted
Tweaked error overlay styles (pt2) (#2208)
* Fixed several of the issues and nits from PR: * Moved margin between header and file name to header, so when content was scrolled, the header would remain more separate * Made build-time and runtime overlays better match * Secondary error <pre> style now uses yellow bg instead of red * 'Scrollable Header' (see above comment to why this is necessary) but I did increase the max-height from 35% to 50%. * Fixed header and 'X' button vertical alignment * Temporary stack margin fix * Move "N errors" to the top
1 parent c82c4f0 commit 0681e24

File tree

5 files changed

+55
-30
lines changed

5 files changed

+55
-30
lines changed

packages/react-dev-utils/webpackHotDevClient.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function overlayHeaderStyle() {
8585
'font-family: sans-serif;' +
8686
'color: rgb(206, 17, 38);' +
8787
'white-space: pre-wrap;' +
88-
'margin: 0.75rem 2rem 0px 0px;' +
88+
'margin: 0 2rem 0.75rem 0px;' +
8989
'flex: 0 0 auto;' +
9090
'max-height: 35%;' +
9191
'overflow: auto;';
@@ -129,9 +129,9 @@ function showErrorOverlay(message) {
129129
// TODO: unify this with our runtime overlay
130130
overlayDiv.innerHTML = '<div style="' +
131131
overlayHeaderStyle() +
132-
'">Failed to compile</div><br><br>' +
132+
'">Failed to compile</div>' +
133133
'<pre style="' +
134-
'display: block; padding: 0.5em; margin-top: 0.5em; ' +
134+
'display: block; padding: 0.5em; margin-top: 0; ' +
135135
'margin-bottom: 0.5em; overflow-x: auto; white-space: pre-wrap; ' +
136136
'border-radius: 0.25rem; background-color: rgba(206, 17, 38, 0.05)">' +
137137
'<code style="font-family: Consolas, Menlo, monospace;">' +

packages/react-error-overlay/src/components/code.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import type { ScriptLine } from '../utils/stack-frame';
33
import { applyStyles } from '../utils/dom/css';
44
import { absolutifyCaret } from '../utils/dom/absolutifyCaret';
55
import {
6-
preStyle,
76
codeStyle,
87
primaryErrorStyle,
8+
primaryPreStyle,
99
secondaryErrorStyle,
10+
secondaryPreStyle,
1011
} from '../styles';
1112

1213
import generateAnsiHtml from 'react-dev-utils/ansiHTML';
@@ -82,7 +83,7 @@ function createCode(
8283
}
8384
}
8485
const pre = document.createElement('pre');
85-
applyStyles(pre, preStyle);
86+
applyStyles(pre, main ? primaryPreStyle : secondaryPreStyle);
8687
pre.appendChild(code);
8788

8889
if (typeof onSourceClick === 'function') {

packages/react-error-overlay/src/components/frame.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import type { StackFrame } from '../utils/stack-frame';
66
import type { FrameSetting, OmitsObject } from './frames';
77
import { applyStyles } from '../utils/dom/css';
88
import {
9-
omittedFramesStyle,
9+
omittedFramesExpandedStyle,
10+
omittedFramesCollapsedStyle,
1011
functionNameStyle,
1112
depStyle,
1213
linkStyle,
@@ -39,12 +40,14 @@ function getGroupToggle(
3940
if (hide) {
4041
text1.textContent = text1.textContent.replace(//, '▶');
4142
text1.textContent = text1.textContent.replace(/expanded/, 'collapsed');
43+
applyStyles(omittedFrames, omittedFramesCollapsedStyle);
4244
} else {
4345
text1.textContent = text1.textContent.replace(//, '▲');
4446
text1.textContent = text1.textContent.replace(/collapsed/, 'expanded');
47+
applyStyles(omittedFrames, omittedFramesExpandedStyle);
4548
}
4649
});
47-
applyStyles(omittedFrames, omittedFramesStyle);
50+
applyStyles(omittedFrames, omittedFramesCollapsedStyle);
4851
return omittedFrames;
4952
}
5053

@@ -73,7 +76,7 @@ function insertBeforeBundle(
7376
div.addEventListener('click', function() {
7477
return actionElement.click();
7578
});
76-
applyStyles(div, omittedFramesStyle);
79+
applyStyles(div, omittedFramesExpandedStyle);
7780
div.style.display = 'none';
7881

7982
parent.insertBefore(div, first);

packages/react-error-overlay/src/components/overlay.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ function createOverlay(
4040
overlay.appendChild(container);
4141
container.appendChild(createClose(document, closeCallback));
4242

43+
// Create "Errors X of Y" in case of multiple errors
44+
const additional = document.createElement('div');
45+
applyStyles(additional, additionalStyle);
46+
updateAdditional(
47+
document,
48+
additional,
49+
currentError,
50+
totalErrors,
51+
switchCallback
52+
);
53+
container.appendChild(additional);
54+
4355
// Create header
4456
const header = document.createElement('div');
4557
applyStyles(header, headerStyle);
@@ -64,18 +76,6 @@ function createOverlay(
6476
header.appendChild(document.createTextNode(finalMessage));
6577
container.appendChild(header);
6678

67-
// Create "Errors X of Y" in case of multiple errors
68-
const additional = document.createElement('div');
69-
applyStyles(additional, additionalStyle);
70-
updateAdditional(
71-
document,
72-
additional,
73-
currentError,
74-
totalErrors,
75-
switchCallback
76-
);
77-
container.appendChild(additional);
78-
7979
// Create trace
8080
container.appendChild(
8181
createFrames(document, frames, frameSettings, contextSize, name)

packages/react-error-overlay/src/styles.js

+31-10
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,24 @@ const closeButtonStyle = {
6464
top: 0,
6565
};
6666

67-
const additionalStyle = {};
67+
const additionalStyle = {
68+
'margin-bottom': '0.5rem',
69+
};
6870

6971
const headerStyle = {
7072
'font-size': '2em',
7173
'font-family': 'sans-serif',
7274
color: red,
7375
'white-space': 'pre-wrap',
74-
margin: '0.75rem 2rem 0 0', // Prevent overlap with close button
76+
// Top bottom margin spaces header
77+
// Right margin revents overlap with close button
78+
margin: '0 2rem 0.75rem 0',
7579
flex: '0 0 auto',
76-
'max-height': '35%',
80+
'max-height': '50%',
7781
overflow: 'auto',
7882
};
7983

80-
const functionNameStyle = {
81-
'margin-top': '1em',
82-
};
84+
const functionNameStyle = {};
8385

8486
const linkStyle = {
8587
'font-size': '0.9em',
@@ -108,12 +110,19 @@ const secondaryErrorStyle = {
108110
'background-color': yellow,
109111
};
110112

111-
const omittedFramesStyle = {
113+
const omittedFramesCollapsedStyle = {
114+
color: black,
115+
cursor: 'pointer',
116+
'margin-bottom': '1.5em',
117+
};
118+
119+
const omittedFramesExpandedStyle = {
112120
color: black,
113121
cursor: 'pointer',
122+
'margin-bottom': '0.6em',
114123
};
115124

116-
const preStyle = {
125+
const primaryPreStyle = {
117126
display: 'block',
118127
padding: '0.5em',
119128
'margin-top': '0.5em',
@@ -123,6 +132,16 @@ const preStyle = {
123132
'border-radius': '0.25rem',
124133
'background-color': 'rgba(206, 17, 38, .05)',
125134
};
135+
const secondaryPreStyle = {
136+
display: 'block',
137+
padding: '0.5em',
138+
'margin-top': '0.5em',
139+
'margin-bottom': '0.5em',
140+
'overflow-x': 'auto',
141+
'white-space': 'pre-wrap',
142+
'border-radius': '0.25rem',
143+
'background-color': 'rgba(251, 245, 180,.3)',
144+
};
126145

127146
const toggleStyle = {
128147
'margin-bottom': '1.5em',
@@ -186,9 +205,11 @@ export {
186205
traceStyle,
187206
depStyle,
188207
primaryErrorStyle,
208+
primaryPreStyle,
189209
secondaryErrorStyle,
190-
omittedFramesStyle,
191-
preStyle,
210+
secondaryPreStyle,
211+
omittedFramesCollapsedStyle,
212+
omittedFramesExpandedStyle,
192213
toggleStyle,
193214
codeStyle,
194215
hiddenStyle,

0 commit comments

Comments
 (0)