question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Symbol polyfill returns strings, creating issues for other libraries

See original GitHub issue

Hi šŸ‘‹

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:closed
  • Created 5 years ago
  • Reactions:15
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
gaearoncommented, Aug 16, 2018

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.

1reaction
brad4dcommented, Aug 16, 2018

Some notes:

  1. closure-compiler does not provide a polyfill for Symbol.for.
  2. closure-compilerā€™s polyfills in general are designed so that if the thing being polyfilled already exists, it is left alone and not replaced.

Given the above, if Symbol.for exists, then our Symbol polyfill should be disabled. So it should be correct that if Symbol.for exists then Symbol() will always return an actual symbol.

Is it possible that thereā€™s another polyfill running on top of ours here?

  1. closure-compiler Symbol polyfill runs early.
  2. another polyfill library loads later and tries to add Symbol.for to our Symbol.
  3. Stuff is broken because the later library assumes it is building on its own Symbol implementation.
Read more comments on GitHub >

github_iconTop Results From Across the Web

ŲŖŁˆŁŠŲŖŲ± \ Š“эŠ½ Ų¹Ł„Ł‰ ŲŖŁˆŁŠŲŖŲ±: "@edparsons @6artvde Seems like this is ...
Symbol polyfill returns strings, creating issues for other libraries Ā· Issue #3052 Ā· google/closu... Hi It seems like GCC ships a low-fidelity Symbol...
Read more >
Module not found: Error: Can't resolve 'core-js/es6'
Ended up to have a file named polyfill.js in projectpath\src\polyfill.js That file only containsĀ ...
Read more >
ES6 Symbols: Drumroll Please! - SitePen
For one, since symbols are primitive types a polyfill cannot correctly replicate typeof checks and Symbol() will return a string.
Read more >
CoffeeScript
Like JavaScript and many other languages, CoffeeScript supports strings as ... not accidentally returning the results of the comprehension in these cases,Ā ...
Read more >
Symbol.iterator - JavaScript - MDN Web Docs
Whenever an object needs to be iterated (such as at the beginning of a for...of loop), its @@iterator method is called with no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found