Skip to content

Commit dc4b731

Browse files
committed
Stop sparkling once disconnected
This could be done by tracking each timeout ID and calling clearTimeout in disconnectedCallback, but checking for isConnected in the timer is enough.
1 parent 887cdea commit dc4b731

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎sparkly-text.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class SparklyText extends HTMLElement {
117117

118118
setTimeout(() => {
119119
const {matches:motionOK} = window.matchMedia('(prefers-reduced-motion: no-preference)');
120-
if (motionOK) this.addSparkle();
120+
if (motionOK && this.isConnected) this.addSparkle();
121121
}, 2000 + Math.random() * 1000);
122122
}
123123
}

0 commit comments

Comments
 (0)