mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Fix production crash (#11286)
* Fix production crash * Add regression test
This commit is contained in:
+1
-1
@@ -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
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user