Skip to content

Commit

Permalink
Fix production crash (#11286)
Browse files Browse the repository at this point in the history
* Fix production crash

* Add regression test
  • Loading branch information
gaearon committed Oct 19, 2017
1 parent 1a81be4 commit 1740f30
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/react-dom/src/ReactDOMFiberComponent.js
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMProduction-test.js
Expand Up @@ -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__ = {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/server/ReactPartialRenderer.js
Expand Up @@ -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');
Expand Down
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 1740f30

Please sign in to comment.