-
Notifications
You must be signed in to change notification settings - Fork 555
fix(Template): Harden Symbol checks in case of incorrect polyfill implementation #2749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Deploy preview for algolia-instantsearch ready! Built with commit 92beae0 https://deploy-preview-2749--algolia-instantsearch.netlify.com |
|
My commits don't pass the check, but it doesn't tell me how/why... |
If a `Symbol` polyfill is present, the instantsearch script presumes that `Symbol` is fully implemented. However, `Symbol` polyfills cannot replicate the behavior fully. This causes the instantsearch script to error out and cause problems on the page if a `Symbol` polyfill is used. This commit hardens the `Symbol` checks to make sure real `Symbol`s are supported, not just a polyfill. NOTE: The google maps API library is a common library that implements a `Symbol` polyfill. @see: * https://stackoverflow.com/questions/48532850/is-google-maps-js-library-polyfilling-symbol * https://stackoverflow.com/questions/39803281/get-typeof-of-the-value-in-es6#39805240
1c1aed4 to
92beae0
Compare
|
Commits didn't pass because it wasn't following the commit convention, I edited them, sorry for the delay, we were having our offsite and looked at PRs with a lower frequency. I think this PR makes sense, but maybe we could even get rid of this function completely in next major (since the react elements as template have been disabled for a few months already) |
|
Do you confirm that this actually fixes the issue though, your screenshot highlights part of code in Preact, not in InstantSearch |
|
@bronzehedwick This seems to be very similar to preactjs/preact-compat#423 (read the comment thread). Since you are also using IE11 |
Yes would also like some more details on this. |
|
Finally I think the issue IS really inside preact-compat since someone asked to strengthen the Symbol check more deeply: preactjs/preact-compat#440 If so we can push for a new release of preact-compat by answering the question from preact author in the PR. On our side we might want to completely remove support for React elements in V2 or in V3.. and delete the code. This is a non-documented feature. For now we could move the const REACT_ELEMENT.. to an inner function so it only runs when someone tries to use React elements as templates. |
We actually removed the support for it. https://community.algolia.com/instantsearch.js/v2/guides/migration.html#react-components-cant-be-used-as-templates However this function is for checking that a user who just migrated is not using them by mistake. I'd say we should keep this message until v3, and therefore keep the check.
I don't think this could work because it will be used to check if this is a react element. Even if it's not a react element. |
|
@Haroenv @vvo Yes, I did confirm this fixed the issue in IE 11. What seemed to be the issue is that Google Maps API defines a Symbol polyfill in the global namespace. I can't make a jsfiddle or some such because I can't expose our Google API keys, but you can confirm this by going to https://mskcc.org/locations/directory in IE, and doing Since Google Maps polyfills Symbol, but the polyfill isn't complete, the check for Symbol comes back "yes" on IE, then, I assume, preact tries to use Symbol methods that the polyfill doesn't support. The Hope that provides enough information. |
|
To recap, there seems to be 2 solutions to this problem:
If the second solution is preferred, what would be the timeline for that? My hunch is that it would be longer than the first. I ask because this bug delayed our Algolia launch, and I'm trying to assess whether we should release with a fork of the code for the time being or wait for a fix from the Algolia team. Thanks! |
There is a misunderstanding here. The code you've fixed is not related to Preact directly, it is a way for us to detect react elements used as templates. Your solution seems fine to me. Eventually we'll move for something that doesn't rely on detection at all :) |
bobylito
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bronzehedwick
|
Great, thanks all! |
Summary
If the Google Maps API
Symbolpolyfill is present (which is included with the library), the instantsearch script presumes thatSymbolis fully implemented. However,Symbolpolyfills cannot replicate the behavior fully.This causes the instantsearch script to error out and cause problems on
the page if a
Symbolpolyfill is used.This commit hardens the
Symbolchecks to make sure realSymbols aresupported, not just a polyfill.
NOTE: The google maps API library is a common library that implements a
Symbolpolyfill.@see:
Result
