Skip to content

Commit

Permalink
Merge pull request #1328 from gaearon/4.12.12
Browse files Browse the repository at this point in the history
4.12.12
  • Loading branch information
theKashey committed Aug 27, 2019
2 parents 67e8fbc + b81dcb0 commit 476e66e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 36 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default hot(App);
module.exports = {
entry: ['react-hot-loader/patch', './src'],
// ...
}
};
```

4. If you need hooks support, use [`@hot-loader/react-dom`](#hot-loaderreact-dom)
Expand Down Expand Up @@ -123,10 +123,10 @@ module.exports = {
// ...
resolve: {
alias: {
'react-dom': '@hot-loader/react-dom'
}
}
}
'react-dom': '@hot-loader/react-dom',
},
},
};
```

### Old API
Expand Down
62 changes: 34 additions & 28 deletions src/errorReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,39 +68,45 @@ const errorHeader = (component, componentStack) => {
return null;
};

const mapError = ({ error, errorInfo, component }) => (
<React.Fragment>
<p style={{ color: 'red' }}>
{errorHeader(component, errorInfo && errorInfo.componentStack)}{' '}
{error.toString ? error.toString() : (error && error.message) || 'undefined error'}
</p>
{errorInfo && errorInfo.componentStack ? (
<div>
<div>Stack trace:</div>
<ul style={{ color: 'red', marginTop: '10px' }}>
{error.stack
.split('\n')
.slice(1, 2)
.map((line, i) => <li key={String(i)}>{line}</li>)}
<hr />
{errorInfo.componentStack
.split('\n')
.filter(Boolean)
.map((line, i) => <li key={String(i)}>{line}</li>)}
</ul>
</div>
) : (
error.stack && (
const mapError = ({ error, errorInfo, component }) => {
if (!error) {
error = { message: 'undefined error' };
}

return (
<React.Fragment>
<p style={{ color: 'red' }}>
{errorHeader(component, errorInfo && errorInfo.componentStack)}{' '}
{error.toString ? error.toString() : (error && error.message) || 'undefined error'}
</p>
{errorInfo && errorInfo.componentStack ? (
<div>
<div>Stack trace:</div>
<ul style={{ color: 'red', marginTop: '10px' }}>
{error.stack.split('\n').map((line, i) => <li key={String(i)}>{line}</li>)}
{error.stack
.split('\n')
.slice(1, 2)
.map((line, i) => <li key={String(i)}>{line}</li>)}
<hr />
{errorInfo.componentStack
.split('\n')
.filter(Boolean)
.map((line, i) => <li key={String(i)}>{line}</li>)}
</ul>
</div>
)
)}
</React.Fragment>
);
) : (
error.stack && (
<div>
<div>Stack trace:</div>
<ul style={{ color: 'red', marginTop: '10px' }}>
{error.stack.split('\n').map((line, i) => <li key={String(i)}>{line}</li>)}
</ul>
</div>
)
)}
</React.Fragment>
);
};

class ErrorOverlay extends React.Component {
state = {
Expand Down
11 changes: 9 additions & 2 deletions src/reconciler/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,12 @@ export function resolveNotComponent(type) {

export const resolveSimpleType = type => resolveProxy(type) || resolveUtility(type) || type;

export const resolveType = (type, options = {}) =>
resolveProxy(type) || resolveUtility(type) || resolveNotComponent(type) || resolveComponent(type, options) || type;
export const resolveType = (type, options = {}) => {
if (!type) {
return type;
}

return (
resolveProxy(type) || resolveUtility(type) || resolveNotComponent(type) || resolveComponent(type, options) || type
);
};
6 changes: 5 additions & 1 deletion src/reconciler/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ const getTypeOf = type => {
return 'Fragment'; // ?
};

function clearStringFast(str) {
return str.length < 12 ? str : ` ${str}`.slice(1);
}

const haveTextSimilarity = (a, b) =>
// equal or slight changed
a === b || levenshtein.get(a, b) < a.length * 0.2;
a === b || levenshtein.get(clearStringFast(a), clearStringFast(b)) < a.length * 0.2;

const getBaseProto = source =>
source.prototype.hotComponentRender ? Object.getPrototypeOf(source.prototype) : source.prototype;
Expand Down
7 changes: 7 additions & 0 deletions test/reactHotLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ describe('reactHotLoader', () => {
const DivProxy = OriginalReactMock.createElement.mock.calls[0][0];
expect(DivProxy[PROXY_KEY]).toBeDefined();
});

it('null case', () => {
reactHotLoader.patch(ReactMock);
const result = React.createElement(undefined);

expect(result.type).toBeUndefined();
});
});

describe('#createFactory', () => {
Expand Down

0 comments on commit 476e66e

Please sign in to comment.