Skip to content

Commit be79d2f

Browse files
committed
fix: do not supress HMR errors
1 parent 3733578 commit be79d2f

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

Diff for: src/AppContainer.dev.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import PropTypes from 'prop-types'
33
import defaultPolyfill, { polyfill } from 'react-lifecycles-compat'
44
import logger from './logger'
5-
import { get as getGeneration } from './global/generation'
5+
import { get as getGeneration, hotComparisonOpen } from './global/generation'
66
import configuration from './configuration'
77
import { EmptyErrorPlaceholder, logException } from './errorReporter'
88

@@ -38,9 +38,14 @@ class AppContainer extends React.Component {
3838

3939
componentDidCatch(error, errorInfo) {
4040
logger.error(error)
41+
42+
if (!hotComparisonOpen()) {
43+
// do not log error outside of HMR cycle
44+
return
45+
}
4146
const { errorReporter = configuration.errorReporter } = this.props
4247
if (!errorReporter) {
43-
logException(error, errorInfo)
48+
logException(error, errorInfo, this)
4449
}
4550
this.setState({
4651
error,

Diff for: src/errorReporter.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import React from 'react'
66
import ReactDom from 'react-dom'
77

88
import configuration from './configuration'
9+
import { getComponentDisplayName } from './internal/reactUtils'
910

1011
let lastError = []
1112

@@ -33,15 +34,24 @@ const inlineErrorStyle = {
3334

3435
const listStyle = {}
3536

36-
export const EmptyErrorPlaceholder = () => (
37+
export const EmptyErrorPlaceholder = ({ component }) => (
3738
<span style={inlineErrorStyle} role="img" aria-label="Rect-Hot-Loader Error">
38-
⚛️🔥🤕
39+
⚛️🔥🤕 ({component
40+
? getComponentDisplayName(component.constructor || component)
41+
: 'Unknown location'})
3942
</span>
4043
)
4144

42-
const mapError = ({ error, errorInfo }) => (
45+
const mapError = ({ error, errorInfo, component }) => (
4346
<div>
4447
<p style={{ color: 'red' }}>
48+
{component && (
49+
<span>
50+
({component
51+
? getComponentDisplayName(component.constructor || component)
52+
: 'Unknown location'})
53+
</span>
54+
)}
4555
{error.toString ? error.toString() : error.message || 'undefined error'}
4656
</p>
4757
{errorInfo && errorInfo.componentStack ? (
@@ -129,7 +139,13 @@ export const clearExceptions = () => {
129139
}
130140
}
131141

132-
export const logException = (error, errorInfo) => {
133-
lastError.push({ error, errorInfo })
142+
export const logException = (error, errorInfo, component) => {
143+
// do not suppress error
144+
145+
/* eslint-disable no-console */
146+
console.error(error)
147+
/* eslint-enable */
148+
149+
lastError.push({ error, errorInfo, component })
134150
initErrorOverlay()
135151
}

Diff for: src/reconciler/proxyAdapter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function componentRender() {
8888
if (error && generation === getGeneration()) {
8989
return React.createElement(
9090
configuration.errorReporter || EmptyErrorPlaceholder,
91-
{ error, errorInfo },
91+
{ error, errorInfo, component: this },
9292
)
9393
}
9494
try {
@@ -99,7 +99,7 @@ function componentRender() {
9999
generation: getGeneration(),
100100
}
101101
if (!configuration.errorReporter) {
102-
logException(renderError)
102+
logException(renderError, undefined, this)
103103
}
104104
return componentRender.call(this)
105105
}

0 commit comments

Comments
 (0)