clear-virtualizer 0.1.8 → 0.2.0

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/README.md CHANGED
@@ -244,12 +244,20 @@ scrollToIndex(34567, { align: 'end' });
244
244
  | `center` | In the middle of the viewport |
245
245
  | `end` | At the bottom of the viewport |
246
246
 
247
- If the row is far away and its neighbors were never measured, the hook first jumps to the estimated position, measures the rows around the target, and corrects the position. A manual scroll during that correction cancels it and hands control back to the user.
247
+ If the row is far away and its neighbors were never measured, the hook first jumps to the estimated position, measures the rows around the target, and corrects the position. A manual scroll during that correction cancels it and hands control back to the user. An index outside `[0, count)` is a silent no-op (no error, no clamping) — clamp it yourself if you need clamping semantics.
248
248
 
249
249
  ## estimateSize
250
250
 
251
251
  `estimateSize` is only a starting guess until real measurements arrive. The closer it is to reality, the less rows visually shift on fast scroll through unmeasured regions: underestimated rows overlap until measured, overestimated ones leave temporary gaps. Pass a value near your average row height.
252
252
 
253
+ ## Dynamic data (growing counts, filtering, reordering)
254
+
255
+ `count` may change at any time — appending rows, streaming, filtering — the hook handles it:
256
+
257
+ - **Measured heights survive count changes.** When `count` grows or shrinks, real measurements are kept and re-applied by index; `estimateSize` is called only for indices that did not exist before. Appending rows at the end is therefore seamless.
258
+ - **Measurements are bound to the index, not to the item.** If you filter or reorder the underlying data, index `i` now holds a different item and inherits the previous item's measured height for one or two frames, until `ResizeObserver` re-measures it. This self-corrects with no overlapping rows in the settled state, but expect a brief visual shift right after a filter or sort change.
259
+ - **Row keys.** The examples use `key={item.index}`, which is right for static data. If your data mutates (filtering, sorting, prepending), prefer a stable key from the item itself (`item.id`) — React then reuses the row's DOM node instead of remounting it on every change.
260
+
253
261
  ## SSR
254
262
 
255
263
  Server-side rendering is supported: on the server the hook renders an empty container (`virtualItems: []`, `scrollHeight: 0`) without touching browser APIs. Rows appear after hydration once the scroll container is attached and `ResizeObserver` reports real heights.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-virtualizer",
3
- "version": "0.1.8",
3
+ "version": "0.2.0",
4
4
  "description": "A lightweight React hook for virtualized lists and tables with dynamic row heights, measured automatically",
5
5
  "type": "module",
6
6
  "main": "./lib/index.cjs",
@@ -66,10 +66,17 @@ const { virtualItems, scrollHeight, scrollRef, getMeasureRef, scrollToIndex } =
66
66
  2. **Position rows with `transform: translateY(item.start)`,** inside a `position: relative` spacer of `height: scrollHeight`. Do not use `top` with `absolute` + margins.
67
67
  3. **Call `getMeasureRef(index)` per row index** (it returns a stable callback per index). Attaching one ref to every row corrupts measurements.
68
68
  4. **Pass a realistic `estimateSize`** (average row height). It is only a starting guess until real measurements arrive; underestimates overlap, overestimates leave temporary gaps.
69
- 5. **`scrollToIndex` is not synchronous.** For far-away targets the hook jumps to the estimated position, measures rows around the target, and corrects over the following frames. A user scroll during that settle cancels it and hands control back. Do not assert on `scrollTop` in the same tick.
69
+ 5. **`scrollToIndex` is not synchronous.** For far-away targets the hook jumps to the estimated position, measures rows around the target, and corrects over the following frames. A user scroll during that settle cancels it and hands control back. Do not assert on `scrollTop` in the same tick. An index outside `[0, count)` is a silent no-op.
70
70
  6. **Vertical scrolling only.** No horizontal virtualization, no sticky columns; style wide tables with per-column widths and `flexShrink: 0` so the header and body stay aligned.
71
71
  7. **`headerHeight` shifts the visible window** below a `position: sticky` header; item `start` values stay absolute relative to the content top either way.
72
72
 
73
+ ## Dynamic data (growing counts, filtering, reordering)
74
+
75
+ `count` may change at any time — appending rows, streaming, filtering:
76
+
77
+ - Measured heights survive count changes: they are kept and re-applied by index, and `estimateSize` is called only for indices that did not exist before. Appending at the end is seamless.
78
+ - Measurements are bound to the **index, not the item**. After a filter or reorder, an index inherits the previous item's height for one or two frames until `ResizeObserver` re-measures; it self-corrects. Prefer stable item keys (`item.id`) over `key={item.index}` when data mutates.
79
+
73
80
  ## SSR
74
81
 
75
82
  On the server the hook renders an empty container (`virtualItems: []`, `scrollHeight: 0`) without touching browser APIs. Rows appear after hydration once the scroll container is attached and `ResizeObserver` reports real heights. Initial HTML is deterministic and hydration-safe.