fix(virtual-core): early return in _measureElement for disconnected nodes #1135
main fromrefs/pull/1135/head·merged by piecyk Fixes https://github.com/TanStack/virtual/issues/1133
🎯 Changes#
Fix stale ResizeObserver callbacks corrupting elementsCache after item deletion.
When items are removed from the list, ResizeObserver can still fire for DOM nodes that are no longer connected to the document. Previously, the node.isConnected check was at the bottom of _measureElement, only guarding the resizeItem call. This allowed the cache swap logic above it to run, unobserving the correct element for a key and storing a dead node in its place.
Fix: Move the !node.isConnected check to the top of _measureElement so we bail out before touching any caches. The disconnected node is also unobserved to prevent future stale callbacks.
Additionally, restructured the Playwright e2e test app into a multi-page setup and added an e2e test that reproduces the exact expand, collapse, delete, expand scenario.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested this code locally with
pnpm run test:pr.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
- 1
View your CI Pipeline Execution ↗ for commit d75f9c9143df90f0a6deb65bf8fe92172da4805e
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 9s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 15s View ↗
☁️ Nx Cloud last updated this comment at
2026-03-05 20:21:01UTCMore templates
- @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-react-virtual-example-dynamic
- tanstack-react-virtual-example-fixed
- tanstack-react-virtual-example-infinite-scroll
- tanstack-react-virtual-example-padding
- 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@1135@tanstack/lit-virtual
npm i https://pkg.pr.new/@tanstack/lit-virtual@1135@tanstack/react-virtual
npm i https://pkg.pr.new/@tanstack/react-virtual@1135@tanstack/solid-virtual
npm i https://pkg.pr.new/@tanstack/solid-virtual@1135@tanstack/svelte-virtual
npm i https://pkg.pr.new/@tanstack/svelte-virtual@1135@tanstack/virtual-core
npm i https://pkg.pr.new/@tanstack/virtual-core@1135@tanstack/vue-virtual
npm i https://pkg.pr.new/@tanstack/vue-virtual@1135commit:
25f0d09piecyk merged thisff83e94
piecyk closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: d75f9c9143df90f0a6deb65bf8fe92172da4805e
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 7 packages
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