// Why does a closed panel still react? // Teaching excerpts; see the explanation and boundaries on the episode page. // One signal. One cleanup. const c = new AbortController(); window.addEventListener( "resize", () => layout(panel), { signal: c.signal } ); return () => { c.abort(); panel.remove(); }; // Or keep the same function. const onResize = () => layout(panel); window.addEventListener( "resize", onResize ); // On close: window.removeEventListener( "resize", onResize );