Skip to content

fix(virtual-core): early return in _measureElement for disconnected nodes#1135

Merged
piecyk merged 3 commits intoTanStack:mainfrom
piecyk:fix/issues/1133
Mar 5, 2026
Merged

fix(virtual-core): early return in _measureElement for disconnected nodes#1135
piecyk merged 3 commits intoTanStack:mainfrom
piecyk:fix/issues/1133

Conversation

@piecyk
Copy link
Collaborator

@piecyk piecyk commented Mar 5, 2026

Fixes #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).

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: d75f9c9

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

This PR includes changesets to release 7 packages
Name Type
@tanstack/virtual-core Patch
@tanstack/angular-virtual Patch
@tanstack/lit-virtual Patch
@tanstack/react-virtual Patch
@tanstack/solid-virtual Patch
@tanstack/svelte-virtual Patch
@tanstack/vue-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

@nx-cloud
Copy link

nx-cloud bot commented Mar 5, 2026

View your CI Pipeline Execution ↗ for commit d75f9c9

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:01 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 5, 2026

More templates

@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@1135

commit: 25f0d09

@piecyk piecyk merged commit ff83e94 into TanStack:main Mar 5, 2026
4 checks passed
@github-actions github-actions bot mentioned this pull request Mar 5, 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.

A "surviving" item within the virtualizer gets attached to one deleted from the DOM; fails to update

1 participant