My website uses the prototype.js library - see <ht...
# community-help
j
My website uses the prototype.js library - see http://prototypejs.org/ And as soon as I include this library it kills the Typesense/InstantSearch implementation, giving the error I pasted below. Does anyone know how I could resolve this?
Copy code
uniq.ts:2 Uncaught TypeError: Cannot read property 'indexOf' of undefined
    at uniq.ts:2
    at prototype.js:884
    at prototype.js:825
    at Array.forEach (<anonymous>)
    at Array.each (prototype.js:824)
    at Array.findAll (prototype.js:883)
    at le (uniq.ts:2)
    at prepareTemplateProps.ts:26
    at he (prepareTemplateProps.ts:60)
    at hits.tsx:42
n
Oof, that's an old library. My instinct says it may have something to do with the fact that prototype messes with a lot of built in types. If you are starting a new project it may be worth considering dropping prototype, as everything it offers can be done in vanilla js by now. If it's a legacy website, could you set up a minimal reproducible example somewhere, eg codepen or GitHub?
1
👍 1
j
I won't be able to remove prototype.js easily... The site I am talking about runs under Magento 1.9, which depends on prototype.js unfortunately...
j
@John Doisneau I just dug through that stack trace and I can confirm what Nick mentioned above is indeed the issue. Instantsearch.js uses the
Array.filter
function and the modern JS implementation of it takes 3 parameters. However, Prototype.js redefines
Array.filter
globally as it's own 2-argument function and that causes InstantSearch.js to error out. Not sure if this is helpful, but may be something like this might help prevent prototype polluting the global Array object: http://perrymitchell.net/article/stop-polluting-my-prototypes/
👍 1
j
Thanks @Jason Bosco, very cool link! Now, my website was using prototype.js version 7.0. And upgrading to 7.1 resolved the issue (for now, since I haven't finished my implementation...)
j
Oh awesome!