Symbol polyfill returns strings, creating issues for other libraries
See original GitHub issueHi š
It seems like GCC ships a low-fidelity Symbol polyfill that returns strings. This has broken numerous libraries, including React, which assumes that if Symbol
and Symbol.for
exists, the typeof
of the returned value is not string
(popular polyfills like core-js
return objects).
Unfortunately this issue isnāt isolated to GCC apps. Some Google SDKs (notably, Google Maps SDK) are compiled with GCC, polluting the environment with this polyfill. This is currently breaking every React website that uses Google Maps API in IE11 (https://github.com/facebook/react/issues/13414).
React assumes that if Symbol
and Symbol.for
exist, typeof Symbol()
will never be a string. Violating this leads to very confusing errors for React users. Itās not obvious at all that loading a Maps API will install a low-fidelity polyfill into the global environment.
While arguably both string
and object
values for typeof
are wrong, in practice Symbols most commonly need to be differentiated from strings ā because both can serve as keys. So typically the value is tested as typeof something === 'string'
to disambiguate them (because checking it for 'symbol'
inside a library would only work with native Symbols). Therefore in practice making the typeof
value an object
creates less footguns ā and has been used by popular polyfills like core-js
for a few years.
Happy to provide more details if necessary! You can also find a reproducing project (caused by Google Maps being compiled with GCC) here: https://github.com/jamiewinder/ie11-fragment-issue
Issue Analytics
- State:
- Created 5 years ago
- Reactions:15
- Comments:11 (11 by maintainers)
Top GitHub Comments
Thanks, Iāll note that in the issue. That said itās not always easy because typically main polyfills are bundled with appās JS, but appās JS expects any libraries (like Google Maps) to already have been loaded.
Some notes:
Symbol.for
.Given the above, if
Symbol.for
exists, then ourSymbol
polyfill should be disabled. So it should be correct that ifSymbol.for
exists thenSymbol()
will always return an actual symbol.Is it possible that thereās another polyfill running on top of ours here?
Symbol
polyfill runs early.Symbol.for
to ourSymbol
.Symbol
implementation.