Fix production crash (#11286)

* Fix production crash

* Add regression test
This commit is contained in:
Dan Abramov
2017-10-19 19:12:07 +01:00
committed by GitHub
parent b2fc41ca85
commit 8a7d35a627
4 changed files with 26 additions and 4 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ var HTML = '__html';
var {Namespaces: {html: HTML_NAMESPACE}, getIntrinsicNamespace} = DOMNamespaces;
var getStack = emptyFunction.thatReturnsArgument('');
var getStack = emptyFunction.thatReturns('');
if (__DEV__) {
getStack = getCurrentFiberStackAddendum;
@@ -211,6 +211,28 @@ describe('ReactDOMProduction', () => {
);
});
// Regression test verifying that trying to access (missing) component stack doesn't crash.
it('should throw on children for void elements', () => {
const errorCode = 137;
const container = document.createElement('div');
expect(() =>
ReactDOM.render(<input>children</input>, container),
).toThrowError(
`Minified React error #${errorCode}; visit ` +
`http://facebook.github.io/react/docs/error-decoder.html?invariant=${errorCode}&args[]=input&args[]=` +
' for the full message or use the non-minified dev environment' +
' for full errors and additional helpful warnings.',
);
expect(() =>
ReactDOMServer.renderToString(<input>children</input>, container),
).toThrowError(
`Minified React error #${errorCode}; visit ` +
`http://facebook.github.io/react/docs/error-decoder.html?invariant=${errorCode}&args[]=input&args[]=` +
' for the full message or use the non-minified dev environment' +
' for full errors and additional helpful warnings.',
);
});
it('should not crash with devtools installed', () => {
try {
global.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {
+1 -1
View File
@@ -30,7 +30,7 @@ var omittedCloseTags = require('omittedCloseTags');
var isCustomComponent = require('isCustomComponent');
var toArray = React.Children.toArray;
var getStackAddendum = emptyFunction.thatReturnsArgument('');
var getStackAddendum = emptyFunction.thatReturns('');
if (__DEV__) {
var warning = require('fbjs/lib/warning');
@@ -953,7 +953,7 @@ describe('ReactDOMComponent', () => {
);
});
it('should warn against children for void elements', () => {
it('should throw on children for void elements', () => {
const container = document.createElement('div');
let caughtErr;
try {
@@ -969,7 +969,7 @@ describe('ReactDOMComponent', () => {
);
});
it('should warn against dangerouslySetInnerHTML for void elements', () => {
it('should throw on dangerouslySetInnerHTML for void elements', () => {
const container = document.createElement('div');
let caughtErr;
try {