prop-types
prop-types copied to clipboard
Should the error message for directly calling validator functions be removed in production mode?
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.
You refer to Symbol.prototype[@@toStringTag], but it's absolutely unrelated this problem and Generator.prototype[@@toStringTag].
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?
Without digging the problem, I can say only that Symbol polyfill from core-js should work as expected -)
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";
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.
Fixed in es6-iterator, new version published at v2.0.3