Skip to content

utilities: keep a single pending watch callback - #74

Merged
rameel merged 1 commit into
mainfrom
utilities/watch-pending-callback
Oct 25, 2026
Merged

rameel merged 1 commit into
mainfrom
utilities/watch-pending-callback

Conversation

@rameel

@rameel rameel commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

watch() set a new setTimeout on every effect run but remembered only the last one. When the effect ran more than once before the timers fired, for example after a change made in the same tick as an immediate watcher was created, the callback ran once per timer: the extra calls repeated the latest value with the old value equal to the new one. Disposal cancelled only the last timer, so the earlier ones still fired after it.

Cancel the pending timer before setting a new one, so the callback runs once with the latest value and disposal cancels it. This affects the one-way x-bound bindings (.in and .out) and x-router.

watch() defers the callback with setTimeout on every effect run, but
remembered only the last timer. When the effect ran more than once
before the timers fired, e.g. after a change made in the same tick as
an immediate watch was created, every timer called the callback, and
all of them read the same latest value: the first reported the change,
the rest reported it again with the old value equal to the new one.
The disposer cancelled only the last timer, so the earlier ones still
fired after disposal.

Cancel the pending timer before setting a new one. The callback now
runs once with the latest value, and disposal cancels it.
@github-actions

Copy link
Copy Markdown

📦 Bundle size comparison

Name Size Gzip Brotli Δ
alpinegear-bound.esm.min.js 3.96 KiB (+16 B) 1.81 KiB (+2 B) 1.57 KiB (+1 B) 🔴
alpinegear-bound.min.js 4.00 KiB (+16 B) 1.83 KiB (+1 B) 1.59 KiB (+4 B) 🔴
alpinegear-destroy.esm.min.js 128 B 123 B 91 B
alpinegear-destroy.min.js 191 B 167 B 123 B
alpinegear-dialog.esm.min.js 1.75 KiB 951 B 811 B
alpinegear-dialog.min.js 1.79 KiB 967 B 822 B
alpinegear-format.esm.min.js 1.18 KiB 645 B 579 B
alpinegear-format.min.js 1.25 KiB 680 B 587 B
alpinegear-fragment.esm.min.js 1.51 KiB 785 B 667 B
alpinegear-fragment.min.js 1.57 KiB 817 B 700 B
alpinegear-hotkey.esm.min.js 1.97 KiB 1.08 KiB 964 B
alpinegear-hotkey.min.js 2.03 KiB 1.10 KiB 996 B
alpinegear-main.esm.min.js 7.76 KiB (+16 B) 3.17 KiB (+3 B) 2.79 KiB (-7 B) 🔴
alpinegear-main.min.js 7.73 KiB (+16 B) 3.12 KiB (+3 B) 2.74 KiB (+2 B) 🔴
alpinegear-markdown.esm.min.js 19.27 KiB 7.26 KiB 6.61 KiB
alpinegear-markdown.min.js 19.32 KiB 7.27 KiB 6.63 KiB
alpinegear-match.esm.min.js 1.98 KiB 1004 B 868 B
alpinegear-match.min.js 2.05 KiB 1.01 KiB 897 B
alpinegear-router.esm.min.js 9.42 KiB (+16 B) 4.03 KiB (+3 B) 3.60 KiB (+2 B) 🔴
alpinegear-router.min.js 9.44 KiB (+16 B) 4.05 KiB (+4 B) 3.61 KiB (+6 B) 🔴
alpinegear-safehtml.esm.min.js 806 B 543 B 457 B
alpinegear-safehtml.min.js 853 B 569 B 485 B
alpinegear-template.esm.min.js 421 B 294 B 219 B
alpinegear-template.min.js 483 B 326 B 246 B
alpinegear-typegrab.esm.min.js 471 B 333 B 277 B
alpinegear-typegrab.min.js 509 B 348 B 294 B
alpinegear-when.esm.min.js 1.71 KiB 883 B 761 B
alpinegear-when.min.js 1.77 KiB 914 B 787 B

@rameel
rameel merged commit 3aa5b5b into main Oct 25, 2026
2 checks passed
@rameel
rameel deleted the utilities/watch-pending-callback branch October 25, 2026 19:15
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