This site overrides Array.from() errors on Magento using prototypejs
Asked Answered
C

2

5

Magento 1 use prototypejs, this library overrides Array.form line 1081 in its 1.7 version:

Array.from = $A;

This cause the following JavaScript error in the Console:

This site overrides Array.from() with an implementation that doesn't support iterables, which could cause Google Maps JavaScript API v3 to not work correctly.

Editing this core library does not seem reasonable, how do Magento developers deal with this conflict ?

Clo answered 17/10, 2019 at 9:56 Comment(0)
L
8

I think I have found a solution. Replace the line array.from($A) by this :

function isIterable(obj) {
  // checks for null and undefined
  if (obj == null) {
    return false;
  }
  return typeof obj[Symbol.iterator] === 'function';
}
if (isIterable($A)) {
  Array.from = $A;
}
Loosing answered 18/10, 2019 at 12:37 Comment(3)
Thanks for your suggestion. The error is gone, it doesn't enter the if statement. I will put this in my test environment for a few weeks, hoping it doesn't have side effects.Clo
I implemented this on an old M1 shop I maintain, and it appears to be working without any side effects.Applicative
This is amazing! Thank you. I don't understand though why prototype have not updated their code to fix this.Kimber
T
1

A similar issue has been reported in our Public Issue Tracker and already been addressed by our Engineering team. As per latest comment:

We've just submitted an update for this. The check is now more explicit and will cover your use case: Array.from(new Set([42]))[0] !== 42 ... warn

This will be available in an upcoming weekly release

Public Issue Tracker is a tool used internally at Google to track bugs and feature requests during product development. It is available outside of Google for use by external public and partner users who need to collaborate with Google teams on specific projects. You can learn more here https://developers.google.com/issue-tracker/.

Thrasonical answered 5/11, 2019 at 7:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.