Fix error on element leave