-
Notifications
You must be signed in to change notification settings - Fork 12
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
Call clearInterval
after setInterval
when needed
#1583
Conversation
This fixes a bug where the `setInterval` would continue firing after the user navigates from one dandiset to a new dandiset. This would result in unexpected behavior, such as the overwriting of the new dandiset with the metadata from the old one retrieved by the `setInterval` call.
Vue docs explicitly mention
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you changed the function from setInterval()
to window.setInterval()
, did the typechecking errors go away? This Stack Overflow question (which you may already have seen) talks about the difference between the web and Node versions of setInterval()
and suggests a TypeScript idiom that would work for both environments (and allow you not to include the window.
prefix).
Yeah, I saw that SO answer. I couldn't get it to work, it causes this error for me - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If others are happy with this, then it LGTM.
if (timer === undefined) { | ||
throw Error('Invalid timer value'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To the extent that we think it's actually an error condition if the timer is not set at this point, this is fine. If it ever happens that we want to cancel the interval timer for some other reason, then I think we would invert this conditional, remove the throw
statement, and not worry about a non-existing timer.
UPDATED TO ADD: I understand this code appears this way largely for typechecking reasons. My suggestions about the importance of recognizing this as an error condition would preserve the typechecking functions while omitting the raising of an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll also add, the throw
statement has the advantage of causing a sentry error if it somehow ever did get called.
🚀 PR was released in |
This fixes a bug where the
setInterval
would continue firing after the user navigates from one dandiset to a new dandiset. This would result in unexpected behavior, such as the overwriting of the new dandiset with the metadata from the old one retrieved by thesetInterval
call.One note about the changes - I changed the use of
setInterval
towindow.setInterval
. I couldn't get TypeScript to play nicely with the return value ofsetInterval
for some reason; it was trying to get me to import a type from NodeJS, but since we're in a browser environment it was erroring out. They are functionally identical though.