Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reinitialize causes DOMException for missing or moved child node on Chrome Browser #152

Open
4lki opened this issue Jan 6, 2021 · 6 comments

Comments

@4lki
Copy link

4lki commented Jan 6, 2021

The error occurs, whenever the order config gets updated and is caused by the reinitialize function.

As an error example i point to the project-demo at https://enngage.github.io/ngx-paypal/.
Just change the Dollar amount of the order and get this:
ERROR DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is no longer a child of this node. Perhaps it was moved in response to a mutation?
The error is kind of odd, because it removes the child node as expected, but still throws an error.
So as a workaround just catching the error works.

Deps:
Angular 11
ngx-paypal 6.2.0

@4lki 4lki changed the title reinitialize causes DOMException for missing or moved child node reinitialize causes DOMException for missing or moved child node on Chrome Browser Jan 6, 2021
@4lki
Copy link
Author

4lki commented Jan 6, 2021

Update The error seems to only be occurring on Chromium based Browsers (Tested in Chrome and Android WebView).

@huntonas
Copy link

I am also seeing this is Chrome but not Firefox. Any updates?

@huntonas
Copy link

@4lki I am catching the error, but the btn is still going away. Any chance you can give an example of how you are handling it?

@4lki
Copy link
Author

4lki commented Jan 18, 2021

@huntonas Ok, my first hotfix was to alter this:

if (this.payPalButtonContainerElem) {
                while (this.payPalButtonContainerElem.nativeElement.firstChild) {
                    this.payPalButtonContainerElem.nativeElement.removeChild(this.payPalButtonContainerElem.nativeElement.firstChild);
                }
            }

into this :

if (this.payPalButtonContainerElem) {
                try{
                    while (this.payPalButtonContainerElem.nativeElement.firstChild) {
                        this.payPalButtonContainerElem.nativeElement.removeChild(this.payPalButtonContainerElem.nativeElement.firstChild);
                    }
                }catch(e){}
            }

on line 313 of ngx-paypal.js

...but since i didn't want to fork this repo and maintain my hotfix, i found a template based solution:

By not updating the component config, but recreating it with an ngIf Clause it never calls for reinitialize():

<ngx-paypal ngIf="payPalConfig" (scriptLoaded)="scriptLoaded($event)" [config]="payPalConfig"></ngx-paypal>

then simply set your payPalConfig to undefined first, to clear it from view before updating your payPalConfig.

updateConfig(config:any){
    this.payPalConfig = undefined;
    setTimeout(x => {
      this.paypalConfig = config;
    },200)
  }

Hope this helps

@daniel-ilan
Copy link

I am getting the exact same issue, thanks for the solution. This needs to be resolved by the maintainers of this library

@Slooti
Copy link

Slooti commented May 10, 2021

+1 - would appreciate a fix for this very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants