@samitouri / QOS-React-2 / commits / 1740f30d5c

Fix production crash (#11286)

* Fix production crash * Add regression test

Dan Abramov committed Oct 19, 2017 at 19:12 UTC 1740f30d5caf4153319c7944c6d2b9ba79b6f317
4 files changed +26 -4
packages/react-dom/src/ReactDOMFiberComponent.js
+1 -1
@@ -61,7 +61,7 @@ var HTML = '__html';
61
62 var {Namespaces: {html: HTML_NAMESPACE}, getIntrinsicNamespace} = DOMNamespaces;
63
64 -var getStack = emptyFunction.thatReturnsArgument('');
64 +var getStack = emptyFunction.thatReturns('');
65
66 if (__DEV__) {
67 getStack = getCurrentFiberStackAddendum;
packages/react-dom/src/__tests__/ReactDOMProduction-test.js
+22
@@ -211,6 +211,28 @@ describe('ReactDOMProduction', () => {
211 );
212 });
213
214 + // Regression test verifying that trying to access (missing) component stack doesn't crash.
215 + it('should throw on children for void elements', () => {
216 + const errorCode = 137;
217 + const container = document.createElement('div');
218 + expect(() =>
219 + ReactDOM.render(<input>children</input>, container),
220 + ).toThrowError(
221 + `Minified React error #${errorCode}; visit ` +
222 + `http://facebook.github.io/react/docs/error-decoder.html?invariant=${errorCode}&args[]=input&args[]=` +
223 + ' for the full message or use the non-minified dev environment' +
224 + ' for full errors and additional helpful warnings.',
225 + );
226 + expect(() =>
227 + ReactDOMServer.renderToString(<input>children</input>, container),
228 + ).toThrowError(
229 + `Minified React error #${errorCode}; visit ` +
230 + `http://facebook.github.io/react/docs/error-decoder.html?invariant=${errorCode}&args[]=input&args[]=` +
231 + ' for the full message or use the non-minified dev environment' +
232 + ' for full errors and additional helpful warnings.',
233 + );
234 + });
235 +
236 it('should not crash with devtools installed', () => {
237 try {
238 global.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {
packages/react-dom/src/server/ReactPartialRenderer.js
+1 -1
@@ -30,7 +30,7 @@ var omittedCloseTags = require('omittedCloseTags');
30 var isCustomComponent = require('isCustomComponent');
31
32 var toArray = React.Children.toArray;
33 -var getStackAddendum = emptyFunction.thatReturnsArgument('');
33 +var getStackAddendum = emptyFunction.thatReturns('');
34
35 if (__DEV__) {
36 var warning = require('fbjs/lib/warning');
packages/react-dom/src/shared/__tests__/ReactDOMComponent-test.js
+2 -2
@@ -953,7 +953,7 @@ describe('ReactDOMComponent', () => {
953 );
954 });
955
956 - it('should warn against children for void elements', () => {
956 + it('should throw on children for void elements', () => {
957 const container = document.createElement('div');
958 let caughtErr;
959 try {
@@ -969,7 +969,7 @@ describe('ReactDOMComponent', () => {
969 );
970 });
971
972 - it('should warn against dangerouslySetInnerHTML for void elements', () => {
972 + it('should throw on dangerouslySetInnerHTML for void elements', () => {
973 const container = document.createElement('div');
974 let caughtErr;
975 try {