Skip to content

fix(solid-virtual): preserve measurements on option updates#1203

Open
Hona wants to merge 1 commit into
TanStack:mainfrom
Hona:fix/solid-preserve-measurements
Open

fix(solid-virtual): preserve measurements on option updates#1203
Hona wants to merge 1 commit into
TanStack:mainfrom
Hona:fix/solid-preserve-measurements

Conversation

@Hona

@Hona Hona commented Jun 16, 2026

Copy link
Copy Markdown

Summary

  • replace the Solid adapter's full measure() invalidation on reactive option updates with the normal virtualizer update lifecycle
  • publish virtual items and total size through Solid without clearing measured item sizes
  • add the Solid adapter's first library regression test

This aligns Solid with the lifecycle used by the other adapters:

  • React calls setOptions() during render and _willUpdate() after commit
  • Vue calls setOptions(), _willUpdate(), then triggerRef()
  • Svelte calls setOptions(), _willUpdate(), then explicitly publishes its store
  • Solid now calls setOptions(), _willUpdate(), then explicitly publishes its virtual items and total size

The framework publication mechanism differs, but reactive option updates no longer trigger a full measurement invalidation only in Solid.

OpenCode hit this while migrating its long desktop chat timeline from Virtua to TanStack Virtual. Streaming messages, prepended history, and asynchronously resizing tool output require retained visible rows to preserve their measurements; clearing them on a reactive count update caused temporary estimated geometry and visible movement.

The regression test measures a row at 100px, reactively increases count, and verifies the measurement and resulting total size remain intact.

Fixes #1197

Downstream context: anomalyco/opencode#32331
Downstream patch: https://github.com/anomalyco/opencode/blob/refactor/tanstack-virtual-session/patches/%40tanstack%252Fsolid-virtual%403.13.28.patch

Verification

  • pnpm --filter @tanstack/solid-virtual test:lib --run
  • pnpm --filter @tanstack/solid-virtual test:types
  • pnpm --filter @tanstack/solid-virtual test:eslint
  • pnpm --filter @tanstack/solid-virtual build
  • Prettier check for changed files

Copilot AI review requested due to automatic review settings June 16, 2026 11:19
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

In createVirtualizerBase, the onChange callback now calls instance._willUpdate() and explicitly refreshes virtualItems (via reconcile) and totalSize instead of calling virtualizer.measure(), which previously cleared the item size cache. A regression test, test scripts, and a patch changeset are added.

Changes

Preserve measured sizes on reactive option update

Layer / File(s) Summary
onChange handler fix + test wiring
packages/solid-virtual/src/index.tsx, packages/solid-virtual/package.json, packages/solid-virtual/tests/index.test.ts
Replaces virtualizer.measure() with instance._willUpdate(), setVirtualItems(reconcile(instance.getVirtualItems(), { key: 'index' })), and setTotalSize(instance.getTotalSize()) in the onChange handler. Adds test:lib and test:lib:dev npm scripts. A new Vitest test (preserves measured sizes when reactive options change) creates a virtualizer with reactive count, resizes an item, updates count, and asserts the cached size and total size are correct.
Patch changeset
.changeset/quiet-cats-preserve.md
Adds a Changesets entry for @tanstack/solid-virtual at patch level, noting that measured item sizes are preserved when reactive options change.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐇 A cache once cleared on every change,
Now survives when options rearrange.
_willUpdate is the call,
Measured sizes keep them all—
No estimate needed, what a sweet exchange! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: preserving measurements when reactive options update in the solid-virtual adapter.
Linked Issues check ✅ Passed All code changes directly address issue #1197: replacing measure() with _willUpdate() lifecycle and explicit Solid state publication to preserve measurements on reactive option updates.
Out of Scope Changes check ✅ Passed All changes are in-scope: new test script, measurement preservation fix, and regression test for the solid-virtual adapter per issue #1197 requirements.
Description check ✅ Passed The pull request provides a comprehensive description with clear motivation, technical details, verification steps, and reference to the linked issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates the Solid Virtualizer integration to preserve previously measured item sizes when reactive virtualizer options (e.g., count) change, and adds coverage plus tooling to validate the behavior.

Changes:

  • Replace the reactive-update path to avoid re-measuring in a way that drops cached item sizes.
  • Add a Vitest test verifying measured sizes persist across reactive option updates.
  • Add package scripts to run the library test suite and include a changeset for a patch release.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
packages/solid-virtual/src/index.tsx Changes update flow to preserve measured size cache across reactive option changes.
packages/solid-virtual/tests/index.test.ts Adds a regression test for preserving measured sizes when reactive options change.
packages/solid-virtual/package.json Adds Vitest scripts for running the new test suite.
.changeset/quiet-cats-preserve.md Documents the patch-level behavior change for release notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/solid-virtual/src/index.tsx
Comment thread packages/solid-virtual/package.json
Comment thread packages/solid-virtual/tests/index.test.ts
Comment thread packages/solid-virtual/tests/index.test.ts
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.

solid-virtual: reactive option updates clear measured item sizes

2 participants