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

Hot-reloading crashes when using sprites #43

Open
martinjuhasz opened this issue Oct 5, 2020 · 8 comments
Open

Hot-reloading crashes when using sprites #43

martinjuhasz opened this issue Oct 5, 2020 · 8 comments
Labels
bug Something isn't working

Comments

@martinjuhasz
Copy link

When using sprites, hot reloading does not work anymore.
When react calls commitHookEffectListMount after hot reloading, this gets called in use-sound

React__default.useEffect(function () {
    if (sound) {
      sound.volume(volume);
      sound.rate(playbackRate);
    } // A weird bug means that including the `sound` here can trigger an
    // error on unmount, where the state loses track of the sprites??
    // No idea, but anyway I don't need to re-run this if only the `sound`
    // changes.
    // eslint-disable-next-line react-hooks/exhaustive-deps

  }, [volume, playbackRate]);

where sound.rate(playbackRate); fails in howler because self._sprite is undefined TypeError: self._sprite[sound._sprite] is undefined.

Your comment suggest you're already aware of this issue. This is more a inconvinience than anything serious, so i created this issue just to keep track of this bug.

@joshwcomeau joshwcomeau added the bug Something isn't working label Jun 4, 2021
@drscottlobo
Copy link

I think I am getting an error from the same underlying issue. When I hot reload using my next.js app, I get that error. But I also get a very similar error when doing something as simple as adjusting the volume:

 const [volume, setVolume] = useState(0.75);
    const [play, soundingNote] = useSound([pianoSoundsOgg, pianoSoundsMp3, pianoSoundsM4a], {
        sprite: pianoSoundData.sprite,
        volume: volume,
    });

    function handleChangeVolumeOnClick() {
       if (volume === .75) {
          setVolume(.25)
       }
    }
}

I get the following error:

Unhandled Runtime Error
TypeError: Cannot read properties of undefined (reading '0')

Call Stack
Howl.rate
node_modules/howler/dist/howler.js (1564:0)
eval
node_modules/use-sound/dist/use-sound.esm.js (129:0)
invokePassiveEffectCreate
node_modules/react-dom/cjs/react-dom.development.js (23487:0)
HTMLUnknownElement.callCallback
node_modules/react-dom/cjs/react-dom.development.js (3945:0)
Object.invokeGuardedCallbackDev
node_modules/react-dom/cjs/react-dom.development.js (3994:0)
invokeGuardedCallback
node_modules/react-dom/cjs/react-dom.development.js (4056:0)
flushPassiveEffectsImpl
node_modules/react-dom/cjs/react-dom.development.js (23574:0)
unstable_runWithPriority
node_modules/scheduler/cjs/scheduler.development.js (468:0)
runWithPriority$1
node_modules/react-dom/cjs/react-dom.development.js (11276:0)
flushPassiveEffects
node_modules/react-dom/cjs/react-dom.development.js (23447:0)
eval
node_modules/react-dom/cjs/react-dom.development.js (23324:0)
workLoop
node_modules/scheduler/cjs/scheduler.development.js (417:0)
flushWork
node_modules/scheduler/cjs/scheduler.development.js (390:0)
MessagePort.performWorkUntilDeadline
node_modules/scheduler/cjs/scheduler.development.js (157:0)

@drscottlobo
Copy link

UPDATE:

I found a work around using the exposedData Howl object:

`
const [volume, setVolume] = useState(0.75);
const [play, exposedData] = useSound([pianoSoundsOgg, pianoSoundsMp3, pianoSoundsM4a], {
sprite: pianoSoundData.sprite,
volume: volume,
});

function handleChangeVolumeOnClick() {
   if (volume === .75) {
      setVolume(.25)
      exposedData.sound.volume(.25)  // update howl object volume at the same time as state.
   }
}

}
`

@drscottlobo
Copy link

Ps. Love this Hook by the way, thanks for all your work on it!

@drscottlobo
Copy link

Still hoping this bug might get a fix? It's a bummer to keep having to reload the page with every change since this bug prevents hot reloading.

@rymdmetafor
Copy link

rymdmetafor commented Dec 19, 2022

UPDATE:

I found a work around using the exposedData Howl object:

` const [volume, setVolume] = useState(0.75); const [play, exposedData] = useSound([pianoSoundsOgg, pianoSoundsMp3, pianoSoundsM4a], { sprite: pianoSoundData.sprite, volume: volume, });

function handleChangeVolumeOnClick() {
   if (volume === .75) {
      setVolume(.25)
      exposedData.sound.volume(.25)  // update howl object volume at the same time as state.
   }
}

} `

what is "pianoSoundData.sprite" in your solution?

@drscottlobo
Copy link

drscottlobo commented Jan 6, 2023 via email

@Clueed
Copy link

Clueed commented May 30, 2024

Update for 2024:

const [volume, setVolume] = useState(1)

const [play, exposedData] = useSound(...)

useEffect(() => {
    if (exposedData.sound) exposedData.sound._volume = volume
}, [volume])

exposedData.sound._volume = newVolume

How come there are no well-maintained sound libraries?

@cjinghong
Copy link

When using sprites, hot reloading does not work anymore. When react calls commitHookEffectListMount after hot reloading, this gets called in use-sound

React__default.useEffect(function () {
    if (sound) {
      sound.volume(volume);
      sound.rate(playbackRate);
    } // A weird bug means that including the `sound` here can trigger an
    // error on unmount, where the state loses track of the sprites??
    // No idea, but anyway I don't need to re-run this if only the `sound`
    // changes.
    // eslint-disable-next-line react-hooks/exhaustive-deps

  }, [volume, playbackRate]);

where sound.rate(playbackRate); fails in howler because self._sprite is undefined TypeError: self._sprite[sound._sprite] is undefined.

Your comment suggest you're already aware of this issue. This is more a inconvinience than anything serious, so i created this issue just to keep track of this bug.

Whats wrong with including sound in the useEffect dependency?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants