-
Notifications
You must be signed in to change notification settings - Fork 98
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
no sound when src changes before howlerjs loads asynchronously #85
Comments
Thank you so much for sharing this! I've got the same issue, but your suggestion didn't work for me for some reason. I've modified use-sound.esm.js and use-sound.cjs.development.js but nothing happens. It would be very nice of you if you could please suggest the correct solution. Have a lovely day! |
Eugene, As I understand it, you cannot directly modify a node package. My hope was (is) that the package's author change the source code and republish it on npm. In the meantime (if and until the author makes the changes) you can use the patch-package (https://www.npmjs.com/package/patch-package) to do the patching. Hope this helps, My patch file:
|
Ah, yeah I hadn't really expected this to be used with dynamic / changing sound URLs. The trouble with the proposed fix is that I think the more-idiomatic fix would be to catch the specific case where the Honestly the simplest thing might be to fork this project and load Howler directly (not through a lazy-load). That's not a trade I want to make in this package, but it would be a guaranteed way to solve this problem without any additional code complexity. |
+1 |
1 similar comment
+1 |
My setup:
const [sound, setSound] = useState(null)
const [play] = useSound(sound, ... )
in the useEffect hook I then fetch the sound-url and once fetched set it with setSound(soundSrc)
In my case if the fetch happens "too soon", no sound is played.
The culprit is the lazy loading of howler. As it loads the useEffect hook that is triggered on sound source change runs. The test that ensures the howler component is initialized fails and no further action is taken. Sound source remains unchanged, in my case, as it was null no sound is played.
The solution is trivial, add the howler loading state into the dependency array of the useEffect hook:
React__default.useEffect(function () {
...
}, [JSON.stringify(src), isMounted.current]);
This ensures the hook re-runs once howler is loaded. Now, of course, the hook will also be called every time howler finishes loading, maybe a test should be added to avoid the extra needless initialization of howler inside the hook? Regardless, for me this change alone solved the issue.
The text was updated successfully, but these errors were encountered: