Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
update react-error-overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Feb 8, 2018
1 parent a0aef4d commit 1d120dd
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 44 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ fixtures/
dist/
example-*/
example/
hotDevClient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable */

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
Expand All @@ -18,22 +16,23 @@
// that looks similar to our console output. The error overlay is inspired by:
// https://github.com/glenjamin/webpack-hot-middleware

const SockJS = require('sockjs-client')
const stripAnsi = require('strip-ansi')
const url = require('url')
const launchEditorEndpoint = require('./launch-editor-endpoint')
const formatWebpackMessages = require('./format-webpack-messages')
const ErrorOverlay = require('react-error-overlay')
var SockJS = require('sockjs-client')
var stripAnsi = require('strip-ansi')
var url = require('url')
var launchEditorEndpoint = require('./launchEditorEndpoint')
var formatWebpackMessages = require('./formatWebpackMessages')
var ErrorOverlay = require('react-error-overlay')

ErrorOverlay.setEditorHandler(errorLocation => {
ErrorOverlay.setEditorHandler(function editorHandler(errorLocation) {
// Keep this sync with errorOverlayMiddleware.js
// @TODO: support column number
fetch(
launchEditorEndpoint +
'?file=' +
window.encodeURIComponent(errorLocation.fileName) +
':' +
window.encodeURIComponent(errorLocation.lineNumber || 1)
window.encodeURIComponent(errorLocation.lineNumber || 1) +
':' +
window.encodeURIComponent(errorLocation.colNumber || 1)
)
})

Expand All @@ -43,23 +42,23 @@ ErrorOverlay.setEditorHandler(errorLocation => {
// application. This is handled below when we are notified of a compile (code
// change).
// See https://github.com/facebookincubator/create-react-app/issues/3096
let hadRuntimeError = false
var hadRuntimeError = false
ErrorOverlay.startReportingRuntimeErrors({
onError() {
onError: function() {
hadRuntimeError = true
},
filename: '/static/js/bundle.js'
})

if (module.hot && typeof module.hot.dispose === 'function') {
module.hot.dispose(() => {
module.hot.dispose(function() {
// TODO: why do we need this?
ErrorOverlay.stopReportingRuntimeErrors()
})
}

// Connect to WebpackDevServer via a socket.
const connection = new SockJS(
var connection = new SockJS(
url.format({
protocol: window.location.protocol,
hostname: window.location.hostname,
Expand All @@ -72,7 +71,7 @@ const connection = new SockJS(
// Unlike WebpackDevServer client, we won't try to reconnect
// to avoid spamming the console. Disconnect usually happens
// when developer stops the server.
connection.onclose = function () {
connection.onclose = function() {
if (typeof console !== 'undefined' && typeof console.info === 'function') {
console.info(
'The development server has disconnected.\nRefresh the page if necessary.'
Expand All @@ -81,9 +80,9 @@ connection.onclose = function () {
}

// Remember some state related to hot module replacement.
let isFirstCompilation = true
let mostRecentCompilationHash = null
let hasCompileErrors = false
var isFirstCompilation = true
var mostRecentCompilationHash = null
var hasCompileErrors = false

function clearOutdatedErrors() {
// Clean up outdated compile errors, if any.
Expand All @@ -98,13 +97,13 @@ function clearOutdatedErrors() {
function handleSuccess() {
clearOutdatedErrors()

const isHotUpdate = !isFirstCompilation
var isHotUpdate = !isFirstCompilation
isFirstCompilation = false
hasCompileErrors = false

// Attempt to apply hot updates or reload.
if (isHotUpdate) {
tryApplyUpdates(() => {
tryApplyUpdates(function onHotUpdateSuccess() {
// Only dismiss it when we're sure it's a hot update.
// Otherwise it would flicker right before the reload.
ErrorOverlay.dismissBuildError()
Expand All @@ -116,19 +115,19 @@ function handleSuccess() {
function handleWarnings(warnings) {
clearOutdatedErrors()

const isHotUpdate = !isFirstCompilation
var isHotUpdate = !isFirstCompilation
isFirstCompilation = false
hasCompileErrors = false

function printWarnings() {
// Print warnings to the console.
const formatted = formatWebpackMessages({
warnings,
var formatted = formatWebpackMessages({
warnings: warnings,
errors: []
})

if (typeof console !== 'undefined' && typeof console.warn === 'function') {
for (let i = 0; i < formatted.warnings.length; i++) {
for (var i = 0; i < formatted.warnings.length; i++) {
if (i === 5) {
console.warn(
'There were more warnings in other files.\n' +
Expand All @@ -143,7 +142,7 @@ function handleWarnings(warnings) {

// Attempt to apply hot updates or reload.
if (isHotUpdate) {
tryApplyUpdates(() => {
tryApplyUpdates(function onSuccessfulHotUpdate() {
// Only print warnings if we aren't refreshing the page.
// Otherwise they'll disappear right away anyway.
printWarnings()
Expand All @@ -165,8 +164,8 @@ function handleErrors(errors) {
hasCompileErrors = true

// "Massage" webpack messages.
const formatted = formatWebpackMessages({
errors,
var formatted = formatWebpackMessages({
errors: errors,
warnings: []
})

Expand All @@ -175,7 +174,7 @@ function handleErrors(errors) {

// Also log them to the console.
if (typeof console !== 'undefined' && typeof console.error === 'function') {
for (let i = 0; i < formatted.errors.length; i++) {
for (var i = 0; i < formatted.errors.length; i++) {
console.error(stripAnsi(formatted.errors[i]))
}
}
Expand All @@ -191,8 +190,8 @@ function handleAvailableHash(hash) {
}

// Handle messages from the server.
connection.onmessage = function (e) {
const message = JSON.parse(e.data)
connection.onmessage = function(e) {
var message = JSON.parse(e.data)
switch (message.type) {
case 'hash':
handleAvailableHash(message.data)
Expand Down Expand Up @@ -259,15 +258,15 @@ function tryApplyUpdates(onHotUpdateSuccess) {
}

// https://webpack.github.io/docs/hot-module-replacement.html#check
const result = module.hot.check(/* autoApply */ true, handleApplyUpdates)
var result = module.hot.check(/* autoApply */ true, handleApplyUpdates)

// // Webpack 2 returns a Promise instead of invoking a callback
if (result && result.then) {
result.then(
updatedModules => {
function(updatedModules) {
handleApplyUpdates(null, updatedModules)
},
err => {
function(err) {
handleApplyUpdates(err, null)
}
)
Expand Down
2 changes: 1 addition & 1 deletion packages/poi-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"chalk": "^2.3.0",
"react-error-overlay": "^3.0.0",
"react-error-overlay": "^4.0.0",
"shell-quote": "^1.6.1",
"sockjs-client": "^1.1.4",
"strip-ansi": "^4.0.0"
Expand Down
8 changes: 5 additions & 3 deletions packages/poi/bin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ const watchRun = (app, { devServer, webpackWatcher } = {}) => {
if (!['watch', 'develop'].includes(app.command) && !app.options.watch) return

const filesToWatch = [
...(app.configFile || ['poi.config.js', '.poirc']),
...(app.options.restartOnFileChanges || [])
...[].concat(app.configFile || ['poi.config.js', '.poirc']),
...[].concat(app.options.restartOnFileChanges || [])
]

logger.debug('Watching files', filesToWatch)

const watcher = chokidar.watch(filesToWatch, {
ignoreInitial: true
})
Expand All @@ -57,7 +59,7 @@ const watchRun = (app, { devServer, webpackWatcher } = {}) => {
}

const handleError = err => {
console.error(err)
console.error(err.stack)
process.exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/poi/lib/plugins/baseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ module.exports = poi => {

function setHMR(config) {
const supportHMR = poi.options.hotReload !== false && command === 'develop'
const devClient = require.resolve('poi-dev-utils/hot-dev-client')
const devClient = require.resolve('poi-dev-utils/hotDevClient')

// Add hmr entry using `hotEntry` option
if (supportHMR) {
Expand Down
2 changes: 1 addition & 1 deletion packages/poi/lib/plugins/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const chalk = require('chalk')
const launchEditorMiddlewarre = require('launch-editor-middleware')
const getPort = require('get-port')
const address = require('address')
const launchEditorEndpoint = require('poi-dev-utils/launch-editor-endpoint')
const launchEditorEndpoint = require('poi-dev-utils/launchEditorEndpoint')
const logger = require('../logger')
const unspecifiedAddress = require('../utils/unspecifiedAddress')
const isPath = require('../utils/isPath')
Expand Down
2 changes: 1 addition & 1 deletion packages/poi/test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jest.mock('poi-webpack-node-externals', () =>
)

const oldCwd = process.cwd()
const hotDevClient = require.resolve('poi-dev-utils/hot-dev-client')
const hotDevClient = require.resolve('poi-dev-utils/hotDevClient')

beforeAll(() => {
process.chdir(path.join(__dirname, 'fixture'))
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10297,9 +10297,9 @@ react-dom@^16.0.0, react-dom@^16.2.0:
object-assign "^4.1.1"
prop-types "^15.6.0"

react-error-overlay@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-3.0.0.tgz#c2bc8f4d91f1375b3dad6d75265d51cd5eeaf655"
react-error-overlay@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-4.0.0.tgz#d198408a85b4070937a98667f500c832f86bd5d4"

react-fuzzy@^0.5.1:
version "0.5.1"
Expand Down

0 comments on commit 1d120dd

Please sign in to comment.