Skip to content
Source
Sign inSign up
TanStack/virtual

fix(svelte-virtual): preserve onChange across partial option updates #1344

Mergedclean99(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/1344/headmerged by piecyk

Changes

setOptions({ count }) stops the existing onChange callback even though the setter accepts partial options. Omitted options should remain unchanged; state changes should still invoke the callback.

Keep the user callback separate from the store-notification wrapper in packages/svelte-virtual/src/index.ts. Explicit callback replacement and onChange: undefined still work. With only that source file reverted, both constructors fail the assertion that measure() calls the retained callback exactly once after a count-only update.

Fixes #1343

Checklist

  • Followed the contributing guide and added 8 public-store regression tests.
  • pnpm run test:pr passes: the Svelte checks and all 6 affected example builds pass; root Knip reports the same 3 findings on unchanged main.

Release Impact

  • Published code changes; a patch changeset is included.
  • Docs/CI/dev-only change.

Summary by CodeRabbit

  • Bug Fixes
    • Partial option updates now preserve the existing change callback unless a replacement is provided. Store updates continue to work when no callback is configured.
  • Tests
    • Added coverage for callback preservation, replacement, and clearing, along with store notifications and updated virtualizer values.
    1. 🦋 Changeset detected

      Latest commit: 65d055b100cbf65f8b011a281c8af143d5557429

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 1 package
      NameType
      @tanstack/svelte-virtualPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      • Source mode: Auto
      • Repository: Unavailable
      • Branch: Unavailable
      • File: No configuration file from this repository applied
      • Commit: Unavailable
      • Layers: defaults
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 5f678a7a-88b2-4c60-8cee-a30bc6605792
      Commits

      Reviewing files that changed from the base of the PR and between 18d08351cfd969224fb7353832897cc600b21c30 and 65d055b100cbf65f8b011a281c8af143d5557429.

      Files selected for processing: 6
      • .changeset/tidy-scroll-callbacks.md
      • packages/svelte-virtual/package.json
      • packages/svelte-virtual/src/index.ts
      • packages/svelte-virtual/tests/index.test.ts
      • packages/svelte-virtual/tsconfig.json
      • packages/svelte-virtual/vite.config.ts

      Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

      Walkthrough

      The Svelte virtualizers now retain onChange across partial setOptions updates unless an update replaces or clears it. Tests cover both virtualizer creators and verify callback invocation and store updates.

      Changes: Svelte callback retention

      Layer / File(s)Summary
      Retain onChange across option updates
      packages/svelte-virtual/src/index.ts, .changeset/tidy-scroll-callbacks.md
      createVirtualizerBase initializes and updates the retained callback. Partial updates that omit onChange keep its current value.
      Test callback and store updates
      packages/svelte-virtual/tests/index.test.ts, packages/svelte-virtual/package.json, packages/svelte-virtual/tsconfig.json, packages/svelte-virtual/vite.config.ts
      Tests cover preserving, replacing, and clearing onChange, as well as updates when no callback was initially supplied. The package adds a Vitest script and configures the test directory and TypeScript project files.
      Priority: Normal

      Estimated code review effort: 2 (Simple) | ~15 minutes

      Change: Bug fix · Severity of issue fixed: Low

      Possibly related PRs

      Suggested reviewers: yeungkc, piecyk

      Merge Risk: Minimal · up to 65d05

      The change preserves callbacks across partial option updates while retaining replacement and clearing behavior. No actionable merge-blocking issue remains; merge after normal checks pass.

      Pre-merge checks: Passed 5
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: preserving the onChange callback across partial option updates.
      Description checkPassedThe description includes the required Changes, Checklist, and Release Impact sections. It explains the behavior, test coverage, issue reference, changeset, and the known incomplete pnpm run test:pr …
      Linked Issues checkPassedIssue #1343 requires the existing onChange callback to survive partial setOptions updates for both createVirtualizer and createWindowVirtualizer. packages/svelte-virtual/src/index.ts stores …
      Out of Scope Changes checkPassedThe changes stay within issue #1343. The source change fixes callback retention. The tests, Vitest script, TypeScript inclusion, and Vite test configuration support regression coverage. The patch chan…
      Docstring CoveragePassedNo eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
      Full details: Description check

      Explanation

      The description includes the required Changes, Checklist, and Release Impact sections. It explains the behavior, test coverage, issue reference, changeset, and the known incomplete pnpm run test:pr result.

      Full details: Linked Issues check

      Explanation

      Issue #1343 requires the existing onChange callback to survive partial setOptions updates for both createVirtualizer and createWindowVirtualizer. packages/svelte-virtual/src/index.ts stores the user callback separately, retains it when options.onChange is omitted, and accepts explicit replacement or undefined. The parameterized tests cover both constructors, count-only updates, callback arguments, callback replacement, callback clearing, and store notifications.

      Full details: Out of Scope Changes check

      Explanation

      The changes stay within issue #1343. The source change fixes callback retention. The tests, Vitest script, TypeScript inclusion, and Vite test configuration support regression coverage. The patch changeset documents the fix.

      Full details: Docstring Coverage

      Explanation

      No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files. (3 skipped: 3 unsupported.)

      Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      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.
    3. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 65d055b100cbf65f8b011a281c8af143d5557429

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded18sView ↗
      nx run-many --target=build --exclude=examples/**✅ Succeeded22sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-10-29 08:52:37 UTC

    4. More templates

      @tanstack/angular-virtual

      npm i https://pkg.pr.new/@tanstack/angular-virtual@1344

      @tanstack/lit-virtual

      npm i https://pkg.pr.new/@tanstack/lit-virtual@1344

      @tanstack/marko-virtual

      npm i https://pkg.pr.new/@tanstack/marko-virtual@1344

      @tanstack/react-virtual

      npm i https://pkg.pr.new/@tanstack/react-virtual@1344

      @tanstack/solid-virtual

      npm i https://pkg.pr.new/@tanstack/solid-virtual@1344

      @tanstack/svelte-virtual

      npm i https://pkg.pr.new/@tanstack/svelte-virtual@1344

      @tanstack/virtual-core

      npm i https://pkg.pr.new/@tanstack/virtual-core@1344

      @tanstack/vue-virtual

      npm i https://pkg.pr.new/@tanstack/vue-virtual@1344

      commit: 65d055b

    5. piecyk approved these changes

      Thanks @clean99, nice catch. Keeping the user callback in its own variable is the right fix, since virtualizer.options.onChange is the store wrapper. I ran the new tests against main and the preserve and replace cases fail there, so they cover the bug. Also nice to finally have tests in svelte-virtual 🚀

    6. piecyk merged this6dda0c0

    7. piecyk closed this

Sign in to join this conversation.