Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix production crash #11286

Merged
merged 2 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-dom/src/ReactDOMFiberComponent.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could put the entire error string into this var since it's duplicated below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess.. Just copy paste from above tests. I don't really care. I'll have to get back to this and find another way to test it when I enable production testing of bundles.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no big deal. Just seemed pretty arbitrary the way it was currently setup.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I just don't want to spend time here because I'll delete those tests anyway.

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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