Skip to content

Commit 12107db

Browse files
committed
fix(angular-virtual): capture _didMount cleanup to remove scroll/resize listeners on destroy
afterNextRender discarded the teardown function returned by _didMount(), so observeWindowOffset's scroll and resize listeners were never unregistered. Post-destroy onChange callbacks kept mutating virtualizerSignal, corrupting Angular's reactive graph and causing a "Cannot read properties of null (reading 'flags')" crash on next component creation. Also fixes the cleanup variable type annotation.
1 parent 97a204d commit 12107db

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/angular-virtual': patch
3+
---
4+
5+
fix: capture _didMount cleanup to remove scroll/resize listeners on destroy

packages/angular-virtual/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ function createVirtualizerBase<
7070
{ allowSignalWrites: true },
7171
)
7272

73-
let cleanup: () => void | undefined
74-
afterNextRender({ read: () => (virtualizer ?? lazyInit())._didMount() })
73+
let cleanup: (() => void) | undefined
74+
afterNextRender({
75+
read: () => {
76+
cleanup = (virtualizer ?? lazyInit())._didMount()
77+
},
78+
})
7579

7680
inject(DestroyRef).onDestroy(() => cleanup?.())
7781

0 commit comments

Comments
 (0)