0

I have a JS library (lets call it library 'a') which is an angular app component and is served through a CDN. I also have another library (let call it library 'b') which was written in typescript and transpiled down to es6.

I am loading both these libraries inside of a .Net MVC Knockoutjs application. I am facing an issue, when I load library 'a' it modifies native promises, and library 'b' relies on native promises to perform operations inside it.

If I remove library 'a' from the page and only load library 'b' it works fine.

When I only load library 'b' this is what window.Promise looks like -

enter image description here

When I load library 'a' this is what window.Promise looks like -

enter image description here

And after loading library 'a' if I load library 'b', the Promises inside this library 'b' begins to fail. Seems like all instanceof Promise evaluate to false even if it is a Promise

See below - enter image description here

This is from library 'b'

I am loading these libraries on a user click and add it to DOM using jquery $getScript('', ()=> {})

I am wondering, if there's a way to revert window.Promise back to the native, when I am about to load library 'b'

I am pretty new to Promises, any help is appreciated.

Thanks.

curious_debugger
  • 299
  • 2
  • 8
  • 23
  • 1
    Remove library a – Kevin B Jun 10 '22 at 15:02
  • I wish I could do that, but we need both the library ! I was hoping to reset the promise object right before I make use of library 'b' – curious_debugger Jun 10 '22 at 15:50
  • You can always get the original value *before* something changes it to something else. However, don't be surprised if that also breaks library a. – Kevin B Jun 10 '22 at 15:51
  • Yes, I tried that, I save the native promise when page loads and tried to reassign it right before I make use of library 'b', for some reason it just wouldn't reassign it :( – curious_debugger Jun 10 '22 at 15:56
  • either you did it incorrectly, or you didn't wait until after a assigned it. – Kevin B Jun 10 '22 at 15:58
  • I was able to reset window.promise, direct assignment did not work because when library 'a' loads, it sets window.promise as readonly, so to reset it we should do this - Object.defineProperty(window, "Promise", { writable: true }); and then assign it back. – curious_debugger Jun 13 '22 at 17:54

0 Answers0