locomotivemtl / locomotive-scroll

🛤 Detection of elements in viewport & smooth scrolling with parallax.
https://locomotivemtl.github.io/locomotive-scroll
MIT License
7.54k stars 1.11k forks source link

fix core instance cleanup #528

Closed schardev closed 7 months ago

schardev commented 7 months ago

~Defining an exports field in package.json requires to explicitly declare public exports.~

Also, if you try to destory() the locomotive instance on useEffect cleanup it throws an error:

TypeError: Cannot read properties of undefined (reading 'destroy')

It's coming from the core instance's destroy method, which is undefined by the time the cleanup runs.

Fix it by calling the destroy() method in the next repaint. Not sure if this is the best fix but it Just Works™

Repro: https://codesandbox.io/s/brave-chatelet-8lv3qd

schardev commented 7 months ago

Apologies. Should have opened separate PRs for each. Lemme know if I should.

devenini commented 7 months ago

@schardev could you put the export changes in a new PR please? 🙏

schardev commented 7 months ago

@schardev could you put the export changes in a new PR please? 🙏

Done.