Skip to content

Conversation

@gaearon
Copy link
Collaborator

@gaearon gaearon commented Oct 24, 2017

Fixes #11348.

Instead of completely skipping an invariant that doesn't have a code, now just uses the 'development" version of it with the full message. It does, however, keep it wrapped in the condition, just like #11291 did.

Verified by compiling this file:

/**
 * Copyright (c) 2013-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

'use strict';

var invariant = require('fbjs/lib/invariant');

if (Math.random() > .5) {
  invariant(
    false,
    'Hello world!'
  );
}

if (Math.random() > .5) {
  invariant(
    false,
    'All native instances should have a tag.'
  );
}

module.exports = 42;

Before:

/*
 React v16.0.0
 react.production.min.js

 Copyright (c) 2013-present, Facebook, Inc.

 This source code is licensed under the MIT license found in the
 LICENSE file in the root directory of this source tree.
*/
'use strict';(function(a,b){"object"===typeof exports&&"undefined"!==typeof module?module.exports=b():"function"===typeof define&&define.amd?define(b):a.React=b()})(this,function(){function a(b){for(var c=arguments.length-1,a="Minified React error #"+b+"; visit http://facebook.github.io/react/docs/error-decoder.html?invariant\x3d"+b,d=0;d<c;d++)a+="\x26args[]\x3d"+encodeURIComponent(arguments[d+1]);c=Error(a+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");
c.name="Invariant Violation";c.framesToPop=1;throw c;}.5<Math.random()&&a("17");return 42});

(Note Hello world! is nowhere to be found)

After:

/*
 React v16.0.0
 react.production.min.js

 Copyright (c) 2013-present, Facebook, Inc.

 This source code is licensed under the MIT license found in the
 LICENSE file in the root directory of this source tree.
*/
'use strict';(function(d,a){"object"===typeof exports&&"undefined"!==typeof module?module.exports=a():"function"===typeof define&&define.amd?define(a):d.React=a()})(this,function(){var d=function(b){for(var c=arguments.length-1,a="Minified React error #"+b+"; visit http://facebook.github.io/react/docs/error-decoder.html?invariant\x3d"+b,e=0;e<c;e++)a+="\x26args[]\x3d"+encodeURIComponent(arguments[e+1]);c=Error(a+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");
c.name="Invariant Violation";c.framesToPop=1;throw c;},a=function(b,a,d,e,f,g,h,k){if(!b){if(void 0===a)b=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[d,e,f,g,h,k],l=0;b=Error(a.replace(/%s/g,function(){return c[l++]}));b.name="Invariant Violation"}b.framesToPop=1;throw b;}};.5<Math.random()&&a(!1,"Hello world!");.5<Math.random()&&d("17");return 42});

Note Hello world! is there. (And two versions of invariant are bundled, as expected.)

Also verified extracting errors still works:

/*
 React v16.0.0
 react.production.min.js

 Copyright (c) 2013-present, Facebook, Inc.

 This source code is licensed under the MIT license found in the
 LICENSE file in the root directory of this source tree.
*/
'use strict';(function(a,b){"object"===typeof exports&&"undefined"!==typeof module?module.exports=b():"function"===typeof define&&define.amd?define(b):a.React=b()})(this,function(){var a=function(b){for(var c=arguments.length-1,a="Minified React error #"+b+"; visit http://facebook.github.io/react/docs/error-decoder.html?invariant\x3d"+b,d=0;d<c;d++)a+="\x26args[]\x3d"+encodeURIComponent(arguments[d+1]);c=Error(a+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");
c.name="Invariant Violation";c.framesToPop=1;throw c;};.5<Math.random()&&a("242");.5<Math.random()&&a("17");return 42});

(Note both are codes now, and there's just the prod invariant version bundled.)

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

Nice fix, Dan. Thanks for catching it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants