Skip to content

Commit

Permalink
Replace redbox-react with react-error-overlay (kriasoft#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzzy authored Jun 12, 2017
1 parent 5f06c28 commit 9f4f761
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 49 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@
"pre-commit": "^1.2.2",
"raw-loader": "^0.5.1",
"react-deep-force-update": "^2.0.1",
"react-dev-utils": "^3.0.0",
"react-error-overlay": "^1.0.7",
"react-hot-loader": "^3.0.0-beta.7",
"react-test-renderer": "^15.5.4",
"redbox-react": "^1.4.1",
"rimraf": "^2.6.1",
"sinon": "^2.3.4",
"stylefmt": "^6.0.0",
Expand Down
26 changes: 2 additions & 24 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import React from 'react';
import ReactDOM from 'react-dom';
import ErrorReporter from 'redbox-react';
import deepForceUpdate from 'react-deep-force-update';
import queryString from 'query-string';
import { createPath } from 'history/PathUtils';
Expand Down Expand Up @@ -130,11 +129,7 @@ async function onLocationChange(location, action) {
() => onRenderComplete(route, location),
);
} catch (error) {
// Display the error in full-screen for development mode
if (__DEV__) {
appInstance = null;
document.title = `Error: ${error.message}`;
ReactDOM.render(<ErrorReporter error={error} />, container);
throw error;
}

Expand All @@ -152,31 +147,14 @@ async function onLocationChange(location, action) {
history.listen(onLocationChange);
onLocationChange(currentLocation);

// Handle errors that might happen after rendering
// Display the error in full-screen for development mode
if (__DEV__) {
window.addEventListener('error', (event) => {
appInstance = null;
document.title = `Runtime Error: ${event.error.message}`;
ReactDOM.render(<ErrorReporter error={event.error} />, container);
});
}

// Enable Hot Module Replacement (HMR)
if (module.hot) {
module.hot.accept('./router', () => {
router = require('./router').default;

if (appInstance) {
try {
// Force-update the whole tree, including components that refuse to update
deepForceUpdate(appInstance);
} catch (error) {
appInstance = null;
document.title = `Hot Update Error: ${error.message}`;
ReactDOM.render(<ErrorReporter error={error} />, container);
return;
}
// Force-update the whole tree, including components that refuse to update
deepForceUpdate(appInstance);
}

onLocationChange(currentLocation);
Expand Down
18 changes: 17 additions & 1 deletion tools/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import WriteFilePlugin from 'write-file-webpack-plugin';
import url from 'url';
import querystring from 'querystring';
import launchEditor from 'react-dev-utils/launchEditor';
import run from './run';
import runServer from './runServer';
import webpackConfig from './webpack.config';
Expand Down Expand Up @@ -39,6 +42,7 @@ async function start() {
if (isDebug) {
clientConfig.entry.client = [...new Set([
'babel-polyfill',
'react-error-overlay',
'react-hot-loader/patch',
'webpack-hot-middleware/client',
].concat(clientConfig.entry.client))];
Expand Down Expand Up @@ -75,7 +79,19 @@ async function start() {

proxy: {
target: server.host,
middleware: [wpMiddleware, hotMiddleware],
middleware: [
{
// Keep this in sync with react-error-overlay
route: '/__open-stack-frame-in-editor',
handle(req, res) {
const query = querystring.parse(url.parse(req.url).query);
launchEditor(query.fileName, query.lineNumber);
res.end();
},
},
wpMiddleware,
hotMiddleware,
],
proxyOptions: {
xfwd: true,
},
Expand Down
5 changes: 1 addition & 4 deletions tools/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const config = {
path: path.resolve(__dirname, '../build/public/assets'),
publicPath: '/assets/',
pathinfo: isVerbose,
devtoolModuleFilenameTemplate: info => path.resolve(info.absoluteResourcePath),
},

module: {
Expand Down Expand Up @@ -158,10 +159,6 @@ const config = {

// Exclude dev modules from production build
...isDebug ? [] : [
{
test: path.resolve(__dirname, '../node_modules/redbox-react/lib/index.js'),
use: 'null-loader',
},
{
test: path.resolve(__dirname, '../node_modules/react-deep-force-update/lib/index.js'),
use: 'null-loader',
Expand Down
Loading

0 comments on commit 9f4f761

Please sign in to comment.