@placeholderco/placeholder-ui 2.6.1 → 2.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,11 +33,27 @@
33
33
  // Calculate selected index for background positioning using derived state
34
34
  const selectedIndex = $derived(options.findIndex((option) => option.value === value));
35
35
 
36
+ // Pending timers, cleared on destroy so they never read state after the component is gone
37
+ const pendingTimers = new Set<ReturnType<typeof setTimeout>>();
38
+
39
+ function scheduleRecalculate(delay: number) {
40
+ const id = setTimeout(() => {
41
+ pendingTimers.delete(id);
42
+ recalculateBackground();
43
+ }, delay);
44
+ pendingTimers.add(id);
45
+ }
46
+
36
47
  onMount(() => {
37
48
  // recalculate 10 times on startup to ensure background is positioned correctly
38
49
  for (let i = 0; i < 10; i++) {
39
- setTimeout(() => recalculateBackground(), 100 * i);
50
+ scheduleRecalculate(100 * i);
40
51
  }
52
+
53
+ return () => {
54
+ for (const id of pendingTimers) clearTimeout(id);
55
+ pendingTimers.clear();
56
+ };
41
57
  });
42
58
 
43
59
  // Update background position and size based on selected element
@@ -60,7 +76,7 @@
60
76
  */
61
77
  export function recalculateBackground(delay?: number) {
62
78
  if (delay) {
63
- setTimeout(() => recalculateBackground(), delay);
79
+ scheduleRecalculate(delay);
64
80
  return;
65
81
  }
66
82
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@placeholderco/placeholder-ui",
3
- "version": "2.6.1",
3
+ "version": "2.6.2",
4
4
  "description": "A modern, customizable Svelte 5 UI component library with comprehensive theming support. Re-brand it with a single config object.",
5
5
  "license": "MIT",
6
6
  "author": "Placeholderco",