Skip to content

Robustness: Prevent duplicate timer loops and detached DOM memory leaks - #3

Open
mozluk wants to merge 1 commit into
krakenfx:masterfrom
mozluk:mozluk-patch-1
Open

mozluk wants to merge 1 commit into
krakenfx:masterfrom
mozluk:mozluk-patch-1

Conversation

@mozluk

@mozluk mozluk commented Aug 17, 2026

Copy link
Copy Markdown

Why

Every invocation of the plugin previously created a new interval that retained the selected DOM collection indefinitely, leading to memory leaks and duplicate timer execution.

How
Stored a single timer instance per element using jQuery's .data("timeago-timer"). Added logic to explicitly clear any existing timer (clearInterval(existingTimer)) before initializing a replacement. Introduced an attachment check (isAttached) inside the refresh loop that automatically stops the interval and cleans up the timer data once the element is detached from the document.

Security/Robustness changes
Eliminates client-side memory leaks and CPU exhaustion by ensuring that detached DOM nodes can be properly garbage collected.

Testing
Verified that jquery-timeago/jquery.timeago.js passes standard node --check validation.

Why

Every invocation of the plugin previously created a new interval that retained the selected DOM collection indefinitely, leading to memory leaks and duplicate timer execution.  

How
Stored a single timer instance per element using jQuery's .data("timeago-timer").  Added logic to explicitly clear any existing timer (clearInterval(existingTimer)) before initializing a replacement.  Introduced an attachment check (isAttached) inside the refresh loop that automatically stops the interval and cleans up the timer data once the element is detached from the document.  

Security/Robustness changes
Eliminates client-side memory leaks and CPU exhaustion by ensuring that detached DOM nodes can be properly garbage collected.  

Testing
Verified that jquery-timeago/jquery.timeago.js passes standard node --check validation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant