Vue retains scroll observers after its scroll element becomes null #1352
Describe the bug#
Removing a scroll container while its Vue component stays mounted sets the template ref to null, but virtualizer.value.scrollElement still points to the detached node. A scroll event on that node still invokes onChange.
Your minimal, reproducible example#
https://github.com/clean99/oss-pr-media/tree/main/tanstack-virtual/vue-null-scroll-element
From that directory, run HUSKY=0 LEFTHOOK=0 npm ci --registry=https://registry.npmjs.org && npm run dev and open the local URL.
Steps to reproduce#
- Click Hide catalog. The state shows
getterIsNull: true,attached: true,connected: false, andcleanups: 0. - Click Dispatch detached scroll. The listener still runs:
callbackDelta: 1. - Click Show catalog. The old observer finally cleans up (
cleanups: 1).
Expected behavior#
Hiding the container should clear scrollElement and clean up its observer. A detached scroll should produce callbackDelta: 0.
How often does this bug happen?#
Every time.
Platform#
macOS 26.5.2, Chromium 147.0.0.0, Node.js 24.8.0.
tanstack-virtual version#
@tanstack/vue-virtual 3.13.50, @tanstack/virtual-core 3.19.9, Vue 3.5.22.
TypeScript version#
JavaScript reproduction.
Additional context#
getScrollElement accepts null. The options object and getter stay stable. The reproduction wraps the built-in offset observer to count cleanup and retains the old node to test its listener; it does not measure heap growth.
Terms & Code of Conduct#
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliably reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
piecyk closed this
Sign in to join this conversation.