Fix polling interval leak on SPA navigation

The poll trigger in bind-triggers called set-interval but discarded the
interval ID, so polls continued firing after the element was removed from
the DOM. Now the callback checks el.isConnected each tick and self-clears
when the element is gone (HTMX-style cleanup).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-01 16:44:57 +00:00
parent d1b49db057
commit f5f58ea47e
3 changed files with 30 additions and 8 deletions

View File

@@ -410,9 +410,20 @@
(mods (get trigger "modifiers"))) (mods (get trigger "modifiers")))
(cond (cond
(= kind "poll") (= kind "poll")
(set-interval (let
(fn () (execute-request el nil nil)) ((interval-id nil))
(get mods "interval")) (set!
interval-id
(set-interval
(fn
()
(if
(host-get el "isConnected")
(execute-request el nil nil)
(do
(clear-interval interval-id)
(log-info "poll stopped: element removed"))))
(get mods "interval"))))
(= kind "intersect") (= kind "intersect")
(observe-intersection (observe-intersection
el el

File diff suppressed because one or more lines are too long

View File

@@ -410,9 +410,20 @@
(mods (get trigger "modifiers"))) (mods (get trigger "modifiers")))
(cond (cond
(= kind "poll") (= kind "poll")
(set-interval (let
(fn () (execute-request el nil nil)) ((interval-id nil))
(get mods "interval")) (set!
interval-id
(set-interval
(fn
()
(if
(host-get el "isConnected")
(execute-request el nil nil)
(do
(clear-interval interval-id)
(log-info "poll stopped: element removed"))))
(get mods "interval"))))
(= kind "intersect") (= kind "intersect")
(observe-intersection (observe-intersection
el el