locomotivemtl / locomotive-scroll

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

fix core instance cleanup #528

Closed schardev closed 1 year ago

schardev commented 1 year 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 1 year ago

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

devenini commented 1 year ago

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

schardev commented 1 year ago

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

Done.