@barefootjs/cli 0.34.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.
- package/dist/docs/core/components/portals.md +7 -0
- package/dist/docs/core/reactivity/untrack.md +40 -0
- package/dist/index.js +1162 -934
- package/package.json +5 -5
|
@@ -125,6 +125,13 @@ const handleMount = (el: HTMLElement) => {
|
|
|
125
125
|
|
|
126
126
|
`bf-po` on the moved element lets scoped queries from the owner still find it.
|
|
127
127
|
|
|
128
|
+
`ownerScope` also fixes *where* the element ends up among the container's children. Portal content is always appended to the container immediately — it is in the document from the moment `createPortal` returns, so a `ref` callback can measure it (`offsetWidth`, `getBoundingClientRect()`) in the same tick — and its position settles once its owner is connected:
|
|
129
|
+
|
|
130
|
+
- Owner already connected (hydration — the SSR markup is in the document before `init` runs), or no `ownerScope` given: a single append, at the container's end.
|
|
131
|
+
- Owner not yet connected (a client-side mount — the component's `init`, and so the `ref` callback, runs before whoever called `createComponent()` appends the root): once the owner connects, the element is re-appended, which moves it to the container's end. Pending portals move in creation order, before the next paint.
|
|
132
|
+
|
|
133
|
+
Both construction paths therefore land on the same `document.body` child order — the component root first, then its portals in the order they were created — which decides paint order between overlays with equal `z-index`, focus traversal, and `querySelector` results.
|
|
134
|
+
|
|
128
135
|
|
|
129
136
|
## Dialog Example
|
|
130
137
|
|
|
@@ -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.
|