Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] accumulation of addEventListener callbacks when using fast-reload #163

Open
adrian-kaehler opened this issue Jan 4, 2024 · 2 comments

Comments

@adrian-kaehler
Copy link

adrian-kaehler commented Jan 4, 2024

Describe the bug
When Metro executes a fast-reload, the event listeners are not cleared, but the unregister functions are lost. As a result, every reload creates potentially more and more copies of the callbacks.

To Reproduce
Steps to reproduce the behavior:
Any structure that calls SoundPlayer.addEventListener and stores the unregister function. Change your code, save it. If you are using Metro, it will execute a fast-reload, which will reload the code, clearing your saved unregister functions.

Expected behavior
The behavior is expected, the API is not as needed or expected (more in "Additional Context" below).

Platform (please complete the following information):
In my case, I am developing using Android Studio on Windows 11. I do not expect this behavior to be different in any other environment where Metro is being used.

Additional context
The problem here is not one where the observed behavior is unexpected. The problem, at least as I understand it, is that there is no manual way to clear those callbacks. Compare to, for example, react-native-voice, which has the same issue, but provides a function removeAllCallbacks, that can be used to remove callbacks whose unregister functions are not know, lost, etc. It would seem that react-native-sound-player simply needs such a function.

@cixio
Copy link
Contributor

cixio commented Jun 4, 2024

you always have to remove the listeners yourself, see example:

	React.useEffect(() => {
		const listener = SoundPlayer.addEventListener('FinishedPlaying', () => {
			console.log('FinishedPlaying');
		});
		
		return ()  => {
			listener.remove();
		}
	},[]);

if the problem persists, please show me your code

@hungtooc
Copy link

you always have to remove the listeners yourself, see example:

	React.useEffect(() => {
		const listener = SoundPlayer.addEventListener('FinishedPlaying', () => {
			console.log('FinishedPlaying');
		});
		
		return ()  => {
			listener.remove();
		}
	},[]);

if the problem persists, please show me your code

code worked, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants