kutlugsahin / smooth-dnd

drag and drop library for javascript
MIT License
598 stars 146 forks source link

fix: Executing polyfills code multiple times throws illegal invocation error #92

Open lililili9761 opened 1 year ago

lililili9761 commented 1 year ago

I found out that executing polyfill code multiple times will throw "illegal invocation" error. For the first time runnint the code Z.prototype.firstElementChild == null, we set a getter for Z.prototype.FirstElementChild through Object.defineProperty, which is expected. However, if this polyfill runs again by accident (or just access Z.prototype.firstElementChild), we will get an error. Because inside the Z.prototype.firstElementChild, there is a this.childNodes in getter, which will be intercepted by the browser (I don't know why, I guess Chrome has such a restriction in case we access Node.prototype.childNodes directly), then Uncaught TypeError: Illegal invocation happened. Here's my reproduce url https://jsbin.com/sirihugoya/edit?html,console,output, you can have a check, and you can find an error in devtool console after clicking the "test" button multiple times. @kutlugsahin