evenchange4 / react-grecaptcha

React.js Google reCAPTCHA v2 integration component.
https://react-grecaptcha.netlify.com
MIT License
51 stars 8 forks source link

Unmounting doesn't work in IE #38

Closed jgogstad closed 7 years ago

jgogstad commented 7 years ago

When unmounting the recaptcha in IE, an exception is thrown Object doesn't support property or method 'remove', due to https://github.com/evenchange4/react-grecaptcha/blob/master/src/Recaptcha.js#L48. Which of course is because remove isn't available in IE.

evenchange4 commented 7 years ago

How about simply adding an Element.prototype.remove() polyfill inside your project for IE under Edge? So that react-grecaptcha will not polluting global environment of consumer's project.

if (!('remove' in Element.prototype)) {
    Element.prototype.remove = function() {
        if (this.parentNode) {
            this.parentNode.removeChild(this);
        }
    };
}

ref: https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove

Or, maybe we could use babel-plugin-transform-runtime in react-grecaptcha.

jcdekoning commented 7 years ago

What about changing the code to?

var scriptElement = document.getElementById(ID);
scriptElement.parentNode.removeChild(scriptElement);
evenchange4 commented 7 years ago

@jcdekoning Thanks! 🙌

Sorry I dont have IE browser on my MacBook, please verify the released changes with version v1.1.2 so that I could close it. cc @jgogstad

evenchange4 commented 7 years ago

Close it. Please feel free to reopen this issue if the problem still occurs with a newer version.