@barefootjs/cli 0.35.0 → 0.35.1

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.
@@ -67,3 +67,43 @@ createEffect(() => {
67
67
  setResult(a + b)
68
68
  })
69
69
  ```
70
+
71
+
72
+ ## What `untrack` Does Not Do
73
+
74
+ `untrack` only stops the wrapped read from **registering a dependency**. It does not stop the surrounding effect from **re-running** — and when the effect re-runs for any other reason, the code inside `untrack` runs again too.
75
+
76
+ This matters because BarefootJS groups several bindings into one effect for performance: every reactive attribute on one element shares an effect, and a keyed `.map()` row's attributes and text share a single row effect. When one binding in that group changes, the whole effect re-runs, and every expression in it — untracked or not — is evaluated again.
77
+
78
+ ```tsx
79
+ 'use client'
80
+ import { createSignal, untrack } from '@barefootjs/client'
81
+
82
+ function renderPreview(id: number): string {
83
+ return `<p>Preview for item ${id}</p>`
84
+ }
85
+
86
+ export function Gallery() {
87
+ const [items, setItems] = createSignal([{ id: 1, label: 'First' }, { id: 2, label: 'Second' }])
88
+ const rename = () => setItems(items().map(item => ({ id: item.id, label: item.label + '!' })))
89
+ return (
90
+ <div>
91
+ <button onClick={rename}>Rename all</button>
92
+ <ul>
93
+ {items().map(item => (
94
+ <li key={item.id} title={item.label} data-preview={untrack(() => renderPreview(item.id))}>
95
+ {item.label}
96
+ </li>
97
+ ))}
98
+ </ul>
99
+ </div>
100
+ )
101
+ }
102
+ ```
103
+
104
+ Clicking "Rename all" changes `title` on every row, so every row effect re-runs and `renderPreview` is called again for each row even though it is wrapped in `untrack`. Two guarantees hold regardless:
105
+
106
+ - The untracked read still does not subscribe: a signal read only inside `untrack` never triggers the effect on its own.
107
+ - A DOM write is skipped when the binding's new value is the same as the last one it computed (compared with `Object.is`). `data-preview` above is recomputed on every run but not rewritten, so an attribute whose write is expensive to apply — `srcdoc` on an `<iframe>`, which reloads the frame on every assignment — stays untouched until its value actually changes.
108
+
109
+ If the **computation** itself is what you need to avoid repeating, `untrack` is the wrong tool: put it in a `createMemo` so it only re-runs when its own inputs change.