Skip to content
Source
Sign inSign up
TanStack/virtual

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

Mergedpiecykmerged 3 commits intomain fromrefs/pull/1135/headmerged by piecyk

piecykcommented

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

      🦋 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
      NameType
      @tanstack/virtual-corePatch
      @tanstack/angular-virtualPatch
      @tanstack/lit-virtualPatch
      @tanstack/react-virtualPatch
      @tanstack/solid-virtualPatch
      @tanstack/svelte-virtualPatch
      @tanstack/vue-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. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit d75f9c9143df90f0a6deb65bf8fe92172da4805e

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

      ☁️ Nx Cloud last updated this comment at 2026-03-05 20:21:01 UTC

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

    4. piecyk merged thisff83e94

    5. piecyk closed this

Sign in to join this conversation.