Consider cleaning up the appended Spotify SDK script element and removing event listeners during component unmount to prevent potential memory leaks.
};
return () => {
// Remove the script from the DOM
if (script && script.parentNode) {
script.parentNode.removeChild(script);
}
// Cleanup Spotify.Player instance
const player = playerRef.current;
if (player) {
player.disconnect();
player.removeListener("ready");
player.removeListener("not_ready");
}
// Remove global event listener
window.onSpotifyWebPlaybackSDKReady = null;
};
Originally posted by @Copilot in #130 (comment)