JakubKoralewski / lets-watch-it-together-private

Unconnected fork of LWIT. Private for the duration of SCRUM project.
https://lets-watch-it-together-scrum.herokuapp.com
MIT License
1 stars 0 forks source link

fix(sound): music overlap (fixes #27) #33

Closed JakubKoralewski closed 3 years ago

JakubKoralewski commented 3 years ago

because BackgroundMusic was a regular component any rerenders caused the play function to be called (despite having a hasPlayed ref which should have persisted across re-renders which I dont understand, but whats understandable eis that the useSound hook got a different data parameter and that caused the data.isPlaying to be a false negative). Another way to have fixed this might have been wrapping this component in some sort of memoization React structure that would only re-render this component if the given props have changed (but on second thought this might not have worked, because the BackgroundMusic component was only rerendered because the parent AddFriends was rerendererd as well...

I've decided to change the BackgroundMusic component to be a context, but I don't think it being now a context is what fixed it but rather that it is higher in the DOM hierarchy so it only reloads on the page changing (?) not sure exactly

the MusicProvider is using a context internally so i think this should now enable some UI to be able to change settings like whether sound can play etc.

Yurii17K commented 3 years ago

waiting for it to deploy and reviewing