Skip to content

Commit 93794a6

Browse files
frenzzyokendoken
authored andcommitted
Replace redbox-react with react-error-overlay (#1306)
1 parent 2c2e273 commit 93794a6

File tree

5 files changed

+285
-51
lines changed

5 files changed

+285
-51
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"express": "^4.15.3",
2525
"express-graphql": "^0.6.6",
2626
"express-jwt": "^5.3.0",
27-
"fastclick": "^1.0.6",
2827
"graphql": "^0.10.1",
2928
"graphql-relay": "^0.5.1",
3029
"graphql-sequelize": "^5.3.2",
@@ -116,9 +115,10 @@
116115
"pre-commit": "^1.2.2",
117116
"raw-loader": "^0.5.1",
118117
"react-deep-force-update": "^2.0.1",
118+
"react-dev-utils": "^3.0.0",
119+
"react-error-overlay": "^1.0.7",
119120
"react-hot-loader": "^3.0.0-beta.7",
120121
"react-test-renderer": "^15.5.4",
121-
"redbox-react": "^1.4.1",
122122
"redux-mock-store": "^1.2.3",
123123
"rimraf": "^2.6.1",
124124
"sass-loader": "6.0.3",

src/client.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import React from 'react';
1111
import ReactDOM from 'react-dom';
1212
import { Router } from 'react-router';
13-
import ErrorReporter from 'redbox-react';
1413
import deepForceUpdate from 'react-deep-force-update';
1514
import queryString from 'query-string';
1615
import { createPath } from 'history/PathUtils';
@@ -119,11 +118,7 @@ async function onLocationChange(location, action) {
119118
() => onRenderComplete(location),
120119
);
121120
} catch (error) {
122-
// Display the error in full-screen for development mode
123121
if (__DEV__) {
124-
appInstance = null;
125-
document.title = `Error: ${error.message}`;
126-
ReactDOM.render(<ErrorReporter error={error} />, container);
127122
throw error;
128123
}
129124

@@ -141,29 +136,12 @@ async function onLocationChange(location, action) {
141136
history.listen(onLocationChange);
142137
onLocationChange(currentLocation);
143138

144-
// Handle errors that might happen after rendering
145-
// Display the error in full-screen for development mode
146-
if (__DEV__) {
147-
window.addEventListener('error', (event) => {
148-
appInstance = null;
149-
document.title = `Runtime Error: ${event.error.message}`;
150-
ReactDOM.render(<ErrorReporter error={event.error} />, container);
151-
});
152-
}
153-
154-
// Enable Hot Module Replacement (HMR)
139+
// Enable Hot Module Replacement (HMR)
155140
if (module.hot) {
156141
module.hot.accept('./components/App', () => {
157142
if (appInstance) {
158-
try {
159-
// Force-update the whole tree, including components that refuse to update
160-
deepForceUpdate(appInstance);
161-
} catch (error) {
162-
appInstance = null;
163-
document.title = `Hot Update Error: ${error.message}`;
164-
ReactDOM.render(<ErrorReporter error={error} />, container);
165-
return;
166-
}
143+
// Force-update the whole tree, including components that refuse to update
144+
deepForceUpdate(appInstance);
167145
}
168146

169147
onLocationChange(currentLocation);

tools/start.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import webpack from 'webpack';
1212
import webpackDevMiddleware from 'webpack-dev-middleware';
1313
import webpackHotMiddleware from 'webpack-hot-middleware';
1414
import WriteFilePlugin from 'write-file-webpack-plugin';
15+
import url from 'url';
16+
import querystring from 'querystring';
17+
import launchEditor from 'react-dev-utils/launchEditor';
1518
import run from './run';
1619
import runServer from './runServer';
1720
import webpackConfig from './webpack.config';
@@ -39,6 +42,7 @@ async function start() {
3942
if (isDebug) {
4043
clientConfig.entry.client = [...new Set([
4144
'babel-polyfill',
45+
'react-error-overlay',
4246
'react-hot-loader/patch',
4347
'webpack-hot-middleware/client',
4448
].concat(clientConfig.entry.client))];
@@ -75,7 +79,19 @@ async function start() {
7579

7680
proxy: {
7781
target: server.host,
78-
middleware: [wpMiddleware, hotMiddleware],
82+
middleware: [
83+
{
84+
// Keep this in sync with react-error-overlay
85+
route: '/__open-stack-frame-in-editor',
86+
handle(req, res) {
87+
const query = querystring.parse(url.parse(req.url).query);
88+
launchEditor(query.fileName, query.lineNumber);
89+
res.end();
90+
},
91+
},
92+
wpMiddleware,
93+
hotMiddleware,
94+
],
7995
proxyOptions: {
8096
xfwd: true,
8197
},

tools/webpack.config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const config = {
2929
path: path.resolve(__dirname, '../build/public/assets'),
3030
publicPath: '/assets/',
3131
pathinfo: isVerbose,
32+
devtoolModuleFilenameTemplate: info => path.resolve(info.absoluteResourcePath),
3233
},
3334

3435
module: {
@@ -142,10 +143,6 @@ const config = {
142143

143144
// Exclude dev modules from production build
144145
...isDebug ? [] : [
145-
{
146-
test: path.resolve(__dirname, '../node_modules/redbox-react/lib/index.js'),
147-
use: 'null-loader',
148-
},
149146
{
150147
test: path.resolve(__dirname, '../node_modules/react-deep-force-update/lib/index.js'),
151148
use: 'null-loader',

0 commit comments

Comments
 (0)