container.remove = () => { window.__REACT_SCAN_TOOLBAR_CONTAINER__ = undefined; if (container.hasChildNodes()) { // Double render(null) is needed to fully unmount Preact components. // The first call initiates unmounting, while the second ensures // cleanup of internal VNode references and event listeners. render(null, container); render(null, container); } originalRemove(); };
Coming back to the code snippet shared above, Toolbar uses Preact to render its components but before doing so, previously rendered DOM nodes are removed.
if (container.hasChildNodes()) { // Double render(null) is needed to fully unmount Preact components. // The first call initiates unmounting, while the second ensures // cleanup of internal VNode references and event listeners. render(null, container); render(null, container);}
What’s so special about this? it is called twice and the comment above describes why render is called twice.
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.