Skip to content

Commit 1fa9dfb

Browse files
EHummerstongkatsev
authored andcommitted
docs(react guide): update guide to prevent memory leaks when components are disposed of (#4998)
When a component is disposed of, without calling ReactDOM.unmountComponentAtNode() on the data-reactroot in the destroyed component, the React.Component and videojs.Component (here EpisodeList and vjsEpisodeList) remain in memory. The videojs.Component should listen for its dispose event and unmount its React root in the corresponding React.Component.
1 parent 5d68904 commit 1fa9dfb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

docs/guides/react.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ class vjsEpisodeList extends vjsComponent {
105105
player.ready(() => {
106106
this.mount();
107107
});
108+
109+
/* Remove React root when component is destroyed */
110+
this.on("dispose", () => {
111+
ReactDOM.unmountComponentAtNode(this.el())
112+
});
108113
}
109114

110115
/**

0 commit comments

Comments
 (0)