Skip to content

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

Merged
piecyk merged 1 commit into
TanStack:mainfrom
clean99:contrib/svelte-retain-onchange-partial-options
Oct 29, 2026
Merged

piecyk merged 1 commit into
TanStack:mainfrom
clean99:contrib/svelte-retain-onchange-partial-options

Conversation

@clean99

@clean99 clean99 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

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.

@changeset-bot

changeset-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 65d055b

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

This PR includes changesets to release 1 package
Name Type
@tanstack/svelte-virtual Patch

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

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

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 18d0835 and 65d055b.

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 name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preserving the onChange callback across partial option updates.
Description check Passed 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 …
Linked Issues check Passed Issue #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 check Passed 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 chan…
Docstring Coverage Passed 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. 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.

@nx-cloud

nx-cloud Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 65d055b

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 18s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 22s View ↗

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

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026

Copy link
Copy Markdown
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

@piecyk piecyk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 🚀

@piecyk
piecyk merged commit 6dda0c0 into TanStack:main Oct 29, 2026
10 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 29, 2026
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.

Svelte onChange stops firing after a partial setOptions update

2 participants