Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In debug mode, I noticed that the 'scroll' event listener was still firing, despite the ScrollyVideo component being removed.
After some investigation, I found that this was because
scrollyVideo.destroy()
method was never reached in the React component.this.updateScrollPercentage
in theaddEventListener
preventedremoveEventListener
from destroying it.React Component
(scrollyVideo && scrollyVideo.destroy)
always evaluated false and thescrollyVideo.destroy()
method couldn't be reached.setScrollyVideo
is called inside theuseEffect
hook, and it may not be set when the cleanup function is called.I fixed this by using
useRef
instead ofuseState
to hold thenew ScrollyVideo
.Event Listener
Once
destroy()
could be called, I noticed the event listener was still not being destroyed. After further investigation, I found the anonymous function wrappingthis.updateScrollPercentage()
prevented theremoveEventListener
from finding it.was changed to
Other
These changes were tested in React and Vanilla JS but not Svelte, or Vue (as I don't know anything about them).