Skip to content

Commit

Permalink
Merge pull request woocommerce#65 from woocommerce/fix/unmount-intera…
Browse files Browse the repository at this point in the history
…ctive-blocks

Unmount react component when WpBlock is disconnected
  • Loading branch information
cbravobernal authored Aug 8, 2022
2 parents 7dc3f43 + ad10b34 commit dcb05be
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions assets/js/base/utils/bhe-frontend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { ReactElement } from 'react';
import { unmountComponentAtNode } from 'react-dom';

/**
* Internal dependencies
Expand Down Expand Up @@ -150,6 +151,11 @@ class WpBlock extends HTMLElement {
);
} );
}

disconnectedCallback() {
// Unmount the React component, running callbacks and cleaning up its state.
unmountComponentAtNode( this );
}
}

// We need to wrap the element registration code in a conditional for the same
Expand Down

0 comments on commit dcb05be

Please sign in to comment.