fix(svelte-virtual): preserve onChange across partial option updates #1344
main fromrefs/pull/1344/head·merged 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:prpasses: 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
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.mdpackages/svelte-virtual/package.jsonpackages/svelte-virtual/src/index.tspackages/svelte-virtual/tests/index.test.tspackages/svelte-virtual/tsconfig.jsonpackages/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
onChangeacross partialsetOptionsupdates unless an update replaces or clears it. Tests cover both virtualizer creators and verify callback invocation and store updates.Changes: Svelte callback retention
Priority:Layer / File(s) Summary Retain onChangeacross option updates
packages/svelte-virtual/src/index.ts,.changeset/tidy-scroll-callbacks.mdcreateVirtualizerBaseinitializes and updates the retained callback. Partial updates that omitonChangekeep 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.tsTests 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. NormalEstimated code review effort: 2 (Simple) | ~15 minutes
Change: Bug fix · Severity of issue fixed: Low
Possibly related PRs
- TanStack/virtual#1334: Preserves
onChangeduring partial option updates in the Lit controller adapter.
Suggested reviewers:
yeungkc,piecyk - TanStack/virtual#1334: Preserves
Merge Risk:
Minimal · up to65d05-
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:
5-
Check name Status Explanation Title check The title clearly and concisely describes the main change: preserving the onChangecallback across partial option updates.Description check 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 Issue #1343requires the existingonChangecallback to survive partialsetOptionsupdates for bothcreateVirtualizerandcreateWindowVirtualizer.packages/svelte-virtual/src/index.tsstores …Out of Scope Changes check 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 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:prresult.
Full details: Linked Issues check
-
Explanation
Issue
#1343requires the existingonChangecallback to survive partialsetOptionsupdates for bothcreateVirtualizerandcreateWindowVirtualizer.packages/svelte-virtual/src/index.tsstores the user callback separately, retains it whenoptions.onChangeis omitted, and accepts explicit replacement orundefined. 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.
Comment `@coderabbitai help` to get the list of available commands.-
View your CI Pipeline Execution ↗ for commit 65d055b100cbf65f8b011a281c8af143d5557429
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:37UTCMore templates
- @tanstack/virtual-example-angular-chat
- @tanstack/virtual-example-angular-dynamic
- @tanstack/virtual-example-angular-fixed
- @tanstack/virtual-example-angular-infinite-scroll
- @tanstack/virtual-example-angular-padding
- @tanstack/virtual-example-angular-smooth-scroll
- @tanstack/virtual-example-angular-sticky
- @tanstack/virtual-example-angular-table
- @tanstack/virtual-example-angular-variable
- @tanstack/virtual-example-angular-window
- tanstack-lit-virtual-example-dynamic
- tanstack-lit-virtual-example-fixed
- tanstack-marko-virtual-example-chat
- tanstack-marko-virtual-example-chat-pretext
- tanstack-marko-virtual-example-dynamic
- tanstack-marko-virtual-example-fixed
- tanstack-marko-virtual-example-grid
- tanstack-marko-virtual-example-infinite-scroll
- tanstack-marko-virtual-example-padding
- tanstack-marko-virtual-example-pretext
- tanstack-marko-virtual-example-scroll-padding
- tanstack-marko-virtual-example-smooth-scroll
- tanstack-marko-virtual-example-ssr
- tanstack-marko-virtual-example-ssr-fetch
- tanstack-marko-virtual-example-ssr-restore
- tanstack-marko-virtual-example-ssr-slice
- tanstack-marko-virtual-example-sticky
- tanstack-marko-virtual-example-table
- tanstack-marko-virtual-example-variable
- tanstack-marko-virtual-example-window
- tanstack-marko-virtual-example-window-ssr-slice
- tanstack-react-virtual-example-chat
- tanstack-react-virtual-example-dynamic
- tanstack-react-virtual-example-fixed
- tanstack-react-virtual-example-infinite-scroll
- tanstack-react-virtual-example-padding
- tanstack-react-virtual-example-pretext
- tanstack-react-virtual-example-scroll-padding
- tanstack-react-virtual-example-smooth-scroll
- tanstack-react-virtual-example-sticky
- tanstack-react-virtual-example-table
- tanstack-react-virtual-example-variable
- tanstack-react-virtual-example-window
- tanstack-svelte-virtual-example-dynamic
- tanstack-svelte-virtual-example-fixed
- tanstack-svelte-virtual-example-infinite-scroll
- tanstack-svelte-virtual-example-smooth-scroll
- tanstack-svelte-virtual-example-sticky
- tanstack-svelte-virtual-example-table
- tanstack-vue-virtual-example-dynamic
- tanstack-vue-virtual-example-fixed
- tanstack-vue-virtual-example-infinite-scroll
- tanstack-vue-virtual-example-padding
- tanstack-vue-virtual-example-scroll-padding
- tanstack-vue-virtual-example-smooth-scroll
- tanstack-vue-virtual-example-sticky
- tanstack-vue-virtual-example-table
- tanstack-vue-virtual-example-variable
@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@1344commit:
65d055bpiecyk approved these changes
Thanks @clean99, nice catch. Keeping the user callback in its own variable is the right fix, since
virtualizer.options.onChangeis 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 merged this6dda0c0
piecyk closed this
Sign in to join this conversation.
🦋 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
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