Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtime error overlay #1101

Merged
merged 124 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
2b39275
Add red box prototype
Timer Nov 5, 2016
6c82933
Unmount fail node when hot-reloaded (future proofing)
Timer Nov 27, 2016
2945385
Slightly improve error reason
Timer Nov 27, 2016
c742848
Add Chrome unhandledrejection listener
Timer Nov 27, 2016
a3ae31e
Close red box when Escape is pressed
Timer Nov 27, 2016
60d9aa0
Construct our own source if not available
Timer Nov 27, 2016
57fa69d
Resolve sourcemaps for friendlier traces
Timer Nov 27, 2016
1a7f838
Allow error to be scrolled
Timer Nov 27, 2016
7442984
Only utilize sourcemaps, not the magic. :(
Timer Nov 27, 2016
c12c55b
Make view similar to React Native
Timer Nov 27, 2016
eece957
Fix an uncaught syntax error
Timer Nov 27, 2016
9ffbefb
Add workaround for Firefox 50
Timer Nov 27, 2016
d0b534d
Add a hint for closing the prompt
Timer Nov 27, 2016
91de3e7
Multiple error support
Timer Nov 27, 2016
69b9371
Log any renderer error
Timer Nov 28, 2016
370284a
Dim node_modules in display
Timer Nov 28, 2016
c0300be
Override chrome stack trace limit
Timer Nov 28, 2016
74838e3
Magic: show me some source!
Timer Nov 29, 2016
1fc583e
Add ability to toggle internal calls
Timer Nov 29, 2016
2fad81b
Switch text from show -> hide
Timer Nov 29, 2016
c4e1cc4
Change color scheme to something easier on the eyes
Timer Nov 29, 2016
124ccc8
Change UI to be friendlier (thanks @nicinabox)
Timer Nov 29, 2016
c639d81
Update styles
nicinabox Nov 29, 2016
729ba96
Add container inside overlay
nicinabox Nov 29, 2016
67590d7
Apply pre style
nicinabox Nov 29, 2016
d5220f6
Add line highlight
nicinabox Nov 29, 2016
e1d37f9
Add omitted frames ui
nicinabox Nov 29, 2016
e634d6e
Move yellow to var
nicinabox Nov 29, 2016
f1ec77b
Do all function names in black
nicinabox Nov 29, 2016
965cf91
Adapt container based on screen size
Timer Nov 29, 2016
a3fdf13
Extract ansiHTML
ekosz Nov 29, 2016
4a2b460
Linting
ekosz Nov 29, 2016
6c26595
Add syntax highlighting of errors
ekosz Nov 29, 2016
dda1aac
Linting
Timer Nov 29, 2016
9a92f0f
Remove white background
Timer Nov 29, 2016
519bdb8
Append new files to package.json
Timer Nov 29, 2016
5292b24
Target exact version
Timer Nov 29, 2016
8c11a72
White is a little harsh, use same color as red box.
Timer Nov 29, 2016
57b1673
Fix a bug where omitted frames would never be rendered
Timer Nov 29, 2016
1e27dad
Show local file path instead of confusing webpack://
Timer Nov 29, 2016
b14365b
Do not require the entire file
Timer Nov 29, 2016
46db1ae
Remove css file
ekosz Nov 29, 2016
65d2db5
Use context size, not a magic variable.
Timer Nov 29, 2016
7ea2254
Fix title regression
Timer Nov 30, 2016
ff6e0e1
Update dependency
Timer Nov 30, 2016
a07778e
Do not center text for internal calls
Timer Nov 30, 2016
91f456b
Temporarily disable links
Timer Nov 30, 2016
3ce9bb6
Switch internal toggle to 'i'
Timer Nov 30, 2016
b4567ff
Remove unnecessary rules from container style
nicinabox Nov 30, 2016
18422ab
Reduce omitted frames font size
nicinabox Nov 30, 2016
89f8e71
Fix font family in pre > code
nicinabox Nov 30, 2016
ef940d8
Re-introduce line highlighting
Timer Nov 30, 2016
f95e07c
Object.<anonymous> -> (anonymous function)
Timer Nov 30, 2016
50ae867
Add ability to see script source
Timer Nov 30, 2016
7ba4853
Add missing ansi mappings
Timer Nov 30, 2016
c616c66
Remove SIAF
ekosz Nov 30, 2016
c9982e2
Skip native functions
ekosz Nov 30, 2016
620d0e6
Extract hints div function
ekosz Nov 30, 2016
76ba68f
Extract renderers
ekosz Nov 30, 2016
5c6777a
Refacor var names
ekosz Nov 30, 2016
a6cda06
If source is disabled, don't use the line.
Timer Dec 1, 2016
c031598
Allow toggle between source
Timer Dec 3, 2016
3cc4b42
Allow bundles to be expanded
Timer Dec 3, 2016
b787c31
Wow, how did I let this one slip?
Timer Dec 3, 2016
b05762f
Toggle text for UX/DX
Timer Dec 3, 2016
2ec79ca
Make it so clicking Close unmounts the error component
Timer Dec 3, 2016
5aea0a9
Do not allow hot reloading once an error is thrown
Timer Dec 3, 2016
81fce15
Do not wrap lines for small displays
Timer Dec 3, 2016
00a9048
Fix toggle when additional errors happen
Timer Dec 3, 2016
ede65a6
Make the close a button
Timer Dec 3, 2016
80130ed
Capture and store errors
Timer Dec 4, 2016
4621caf
Dispose on render; move additional logic
Timer Dec 4, 2016
8c24f3d
Only make code not wrap
Timer Dec 4, 2016
c18f09a
Switch to a view-by-index method
Timer Dec 4, 2016
f95fe25
Allow user to switch between errors with arrow keys
Timer Dec 4, 2016
4d3f404
Fix text while switching between errors
Timer Dec 4, 2016
048824f
Update close button style
nicinabox Dec 4, 2016
3a1bfc8
Render additional errors at top
nicinabox Dec 4, 2016
8e64498
Add left and right arrows
Timer Dec 5, 2016
77cd653
Make frames pointy
Timer Dec 5, 2016
872f277
UTF-8 arrows
Timer Dec 5, 2016
db31e1c
Don't mount unneeded DOM node
Timer Dec 5, 2016
10aa816
Switch to single changing text for compiled <-> source
Timer Dec 5, 2016
ee8ec06
Don't display arrows with only one error.
Timer Dec 6, 2016
4d7efad
Collapsed and expanded
Timer Dec 6, 2016
c2a7c54
Make sure the last collapse toggle is appended
Timer Dec 6, 2016
2cc2138
Do not show the stack trace if it doesn't resolve to a file we wrote
Timer Dec 6, 2016
430c240
Style container with media queries
Timer Dec 6, 2016
667a7bd
Do not allow x overflow; break words by default.
Timer Dec 6, 2016
4158ca8
Trim off whitespace of lines
Timer Dec 6, 2016
0e36c66
Remove padding since it's not outer-most
Timer Dec 6, 2016
3a96646
Add footer message
Timer Dec 6, 2016
115cbd3
Extract css file to JS
ekosz Dec 8, 2016
e030bb9
Only inject the css when the overlay is up
Timer Dec 8, 2016
857e0d3
Extract red variable
ekosz Dec 1, 2016
e520870
Remove env
ekosz Dec 1, 2016
8de51ed
Update babel-code-frame
Timer Dec 9, 2016
e05c88d
Set force color to true
Timer Dec 9, 2016
7e2f9b2
Extract out collapse div logic
Timer Dec 9, 2016
5f05432
Remove arrow field
Timer Dec 9, 2016
bcdb069
Insert a top collapse
Timer Dec 9, 2016
ae727b7
Make browser friendlier
Timer Dec 9, 2016
ea4ed6f
Absolutify ^
Timer Dec 10, 2016
9f65765
Make arrows buttons
Timer Dec 10, 2016
7e1660e
Accessify
Timer Dec 10, 2016
8afb167
Let there be ES5
Timer Dec 10, 2016
fe5042c
Pretty css
Timer Dec 10, 2016
ae9c98b
Use forEach where we can ...
Timer Dec 10, 2016
5b4aedd
Remove extracted loop
Timer Dec 10, 2016
5424fd4
Fix IE compatibility
Timer Dec 10, 2016
089eef8
Capture React warnings
Timer Dec 16, 2016
f5a4ec4
Add source override via React output parsing
Timer Dec 17, 2016
fe34c7d
Whoops, fix arguments to crash.
Timer Dec 18, 2016
b7d06d8
Merge branch 'master' into redbox
Timer Feb 11, 2017
640974b
es5-ify
Timer Feb 11, 2017
4a0286f
Merge branch 'master' into redbox
Timer Feb 25, 2017
5c8a8ae
Re-enable e2e-install directory test
Timer Mar 1, 2017
b9de015
Merge branch 'master' into redbox
Timer Mar 1, 2017
a568164
Merge branch 'master' into redbox
Timer Mar 7, 2017
de35346
Only rewrite line number if it was resolved and leaves a line at bottom
Timer Mar 7, 2017
f31e5ab
Rename failFast to crashOverlay
Timer Mar 7, 2017
37ff1cc
Disable console proxy
Timer Mar 7, 2017
2d76dff
Appease linter
Timer Mar 7, 2017
77929a9
Appease more
Timer Mar 7, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions packages/react-dev-utils/ansiHTML.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

var Anser = require('anser');

// Color scheme inspired by https://chriskempson.github.io/base16/css/base16-github.css
// var base00 = 'ffffff'; // Default Background
var base01 = 'f5f5f5'; // Lighter Background (Used for status bars)
// var base02 = 'c8c8fa'; // Selection Background
var base03 = '969896'; // Comments, Invisibles, Line Highlighting
// var base04 = 'e8e8e8'; // Dark Foreground (Used for status bars)
var base05 = '333333'; // Default Foreground, Caret, Delimiters, Operators
// var base06 = 'ffffff'; // Light Foreground (Not often used)
// var base07 = 'ffffff'; // Light Background (Not often used)
var base08 = 'ed6a43'; // Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted
// var base09 = '0086b3'; // Integers, Boolean, Constants, XML Attributes, Markup Link Url
// var base0A = '795da3'; // Classes, Markup Bold, Search Text Background
var base0B = '183691'; // Strings, Inherited Class, Markup Code, Diff Inserted
var base0C = '183691'; // Support, Regular Expressions, Escape Characters, Markup Quotes
// var base0D = '795da3'; // Functions, Methods, Attribute IDs, Headings
var base0E = 'a71d5d'; // Keywords, Storage, Selector, Markup Italic, Diff Changed
// var base0F = '333333'; // Deprecated, Opening/Closing Embedded Language Tags e.g. <?php ?>

// Map ANSI colors from what babel-code-frame uses to base16-github
// See: https://github.com/babel/babel/blob/e86f62b304d280d0bab52c38d61842b853848ba6/packages/babel-code-frame/src/index.js#L9-L22
var colors = {
reset: [base05, 'transparent'],
black: base05,
red: base08, /* marker, bg-invalid */
green: base0B, /* string */
yellow: base08, /* capitalized, jsx_tag, punctuator */
blue: base0C,
magenta: base0C, /* regex */
cyan: base0E, /* keyword */
gray: base03, /* comment, gutter */
lightgrey: base01,
darkgrey: base03
};

var anserMap = {
'ansi-bright-black': 'black',
'ansi-bright-yellow': 'yellow',
'ansi-yellow': 'yellow',
'ansi-bright-green': 'green',
'ansi-green': 'green',
'ansi-bright-cyan': 'cyan',
'ansi-cyan': 'cyan',
'ansi-bright-red': 'red',
'ansi-red': 'red',
'ansi-bright-magenta': 'magenta',
'ansi-magenta': 'magenta'
};

function ansiHTML(txt) {
var arr = new Anser().ansiToJson(txt, {
use_classes: true
});

var result = '';
var open = false;
for (var index = 0; index < arr.length; ++index) {
var c = arr[index];
var content = c.content,
fg = c.fg;

var contentParts = content.split('\n');
for (var _index = 0; _index < contentParts.length; ++_index) {
if (!open) {
result += '<span data-ansi-line="true">';
open = true;
}
var part = contentParts[_index].replace('\r', '');
var color = colors[anserMap[fg]];
if (color != null) {
result += '<span style="color: #' + color + ';">' + part + '</span>';
} else {
if (fg != null) console.log('Missing color mapping: ', fg);
result += '<span>' + part + '</span>';
}
if (_index < contentParts.length - 1) {
result += '</span>';
open = false;
result += '<br/>';
}
}
}
if (open) {
result += '</span>';
open = false;
}
return result;
}

module.exports = ansiHTML;
Loading