-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SetInterval does not clear on HMR reload / code change #91
Comments
Transferring this to the HMR repository. However, as mentioned on the similar issue sveltejs/sites#146 I'm not really sure what would be a reasonable way to resolve this. |
HMR just destroys and recreates your component. If you have a leaking As a general rule that suffers few exceptions, you should make sure that your components always clean after themselves when they get destroyed, and don't leave things like The general pattern is pretty basic, just implement such resources holders in onMount(() => {
const interval = setInterval(() => { ... })
return () => {
clearInterval(interval)
}
} Note that having |
i see, i was able to arrive at the same conclusion, and later used the clear interval in onDestroy....
@rixo @Rich-Harris , this is just primitive idea, will it consider a bad architecture/practice? let me know. |
Describe the bug
this i use to observe changed value
$: {
filterSearchResults(searchTerm);
console.log(selections);
}
------ but this goes out of control and keeps printing forever
setInterval(() => {
console.log(selections);
}, 1000);
Reproduction
this i use to observe changed value
$: {
filterSearchResults(searchTerm);
console.log(selections);
}
------ but this goes out of control and keeps printing forever
setInterval(() => {
console.log(selections);
}, 1000);
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
The text was updated successfully, but these errors were encountered: