prop-types icon indicating copy to clipboard operation
prop-types copied to clipboard

Should the error message for directly calling validator functions be removed in production mode?

Open markusenglund opened this issue 7 years ago • 2 comments

Currently, this package will throw an error when validator functions are called directly in both dev and production mode. Calling validator functions directly was previously supported when PropTypes was bundled with React in < [email protected], so it's understandable that you want to warn developers who are changing to the prop-types package. However, it's been well over a year since directly calling validator functions was deprecated, so the utility of the error message is now considerably less.

My question is: Isn't it enough to warn developers only in dev mode?

By removing the error message from production mode, you could save around 160 bytes gzipped from the final production bundle. That's a paltry number, but since prop-types is bundled in basically every react app in existence it does add up.

markusenglund avatar Jul 15 '18 10:07 markusenglund

You refer to Symbol.prototype[@@toStringTag], but it's absolutely unrelated this problem and Generator.prototype[@@toStringTag].

zloirock avatar Oct 13 '17 17:10 zloirock

Oh sorry you're right! I updated the issue, I'm quite confused with these tags.

Do you have any suggestion on how to tackle this issue? Is there something to polyfill, or a polyfill to fix?

amangeot avatar Oct 14 '17 06:10 amangeot

Without digging the problem, I can say only that Symbol polyfill from core-js should work as expected -)

zloirock avatar Oct 14 '17 16:10 zloirock

Yes that should be safe!

Considering that @@toStringTag is set to writable: false for GeneratorFunction, according to this spec,

is this line ok: Gp[toStringTagSymbol] = "Generator"?


Gp is defined as is:

  var Gp = GeneratorFunctionPrototype.prototype =
    Generator.prototype = Object.create(IteratorPrototype);
  GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  GeneratorFunctionPrototype.constructor = GeneratorFunction;
  GeneratorFunctionPrototype[toStringTagSymbol] =
    GeneratorFunction.displayName = "GeneratorFunction";

amangeot avatar Oct 15 '17 16:10 amangeot

It should be non-writable, but regenerator not so strict. var Gp = Object.create(IteratorPrototype), so the problem in %IteratorPrototype%. regenerator uses %IteratorPrototype% from your environment where it's available, so that means that you have %IteratorPrototype% with non-writable @@toStringTag. It was fixed as writable in polyfill-service, but by the spec %IteratorPrototype% should not have @@toStringTag property.

zloirock avatar Oct 15 '17 17:10 zloirock

Fixed in es6-iterator, new version published at v2.0.3

medikoo avatar Oct 17 '17 11:10 medikoo