Gave a try to backport https://github.com/twbs/bootstrap/pull/33451 to v4.
Feel free to modify it directly or close it if it is too far from what's expected here.
I haven't backported the new unit test it('should remove event listener on touch-enabled device that was added in show method', done => {
because in v4 there was no existing test in that spirit. In v5 there are tests of EventHandler.off
and EventHandler.on
but not in v4.