Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Unmount react component when WpBlock is disconnected #47

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/gutenberg-packages/frontend.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Consumer, createProvider } from './react-context';
import { createGlobal, matcherFromSource } from './utils';
import { EnvContext, hydrate } from './wordpress-element';
import { unmountComponentAtNode } from 'react-dom';

const blockTypes = createGlobal('wpBlockTypes', new Map());

Expand Down Expand Up @@ -179,6 +180,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