Prevent stray polling interval from running and prevent duplicate event listeners #5247
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to: #5230
Bug 1: Multiple event listeners are added to elements
When adding event listeners to elements, Javascript will generally prevent duplicating the listener if the callback function is named. Anonymous functions aren't tracked the same way. Javascript will continue to add an event listener every time the polling happens. This commit names those functions where the listeners are added to elements outside of the "page"
div
.The duplicate event listeners caused some odd behavior:
How to duplicate:
Bug 2: Ghost interval continues polling after clicking "Stop Polling"
Every time the
addListeners
function was called, it would call thescheduleLivePoll()
function and setup a newsetTimeout
. Thus, when you clicked on the "Stop Polling" button, it would continue to poll because of a straysetTimeout
. The only way to stop the polling was to refresh. This commit prevents the function from running if a timeout already exists.How to duplicate:
Note: Above bugs and fixes experienced and tested on Firefox 98.0.1, respectively.