Skip to content

fix(angular-virtual): capture _didMount cleanup to remove scroll/resize listeners on destroy#1159

Open
jsaguet wants to merge 2 commits intoTanStack:mainfrom
jsaguet:fix/angular-cleanup
Open

fix(angular-virtual): capture _didMount cleanup to remove scroll/resize listeners on destroy#1159
jsaguet wants to merge 2 commits intoTanStack:mainfrom
jsaguet:fix/angular-cleanup

Conversation

@jsaguet
Copy link
Copy Markdown
Contributor

@jsaguet jsaguet commented Apr 16, 2026

🎯 Changes

afterNextRender discarded the teardown function returned by _didMount(), so observeWindowOffset's scroll and resize listeners were never unregistered.

Also fixes the cleanup variable type annotation.

✅ 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).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where scroll and resize event listeners were not being properly removed when the Angular virtual component is destroyed, preventing potential memory leaks.

jsaguet and others added 2 commits April 16, 2026 21:13
…ze 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.
@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 16, 2026

View your CI Pipeline Execution ↗ for commit 324a804

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 57s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 14s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-16 19:21:11 UTC

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 98141f4a-2b53-4588-9f6e-088d33d4a938

📥 Commits

Reviewing files that changed from the base of the PR and between 97a204d and 324a804.

📒 Files selected for processing (2)
  • .changeset/fix-angular-virtual-cleanup.md
  • packages/angular-virtual/src/index.ts

📝 Walkthrough

Walkthrough

A patch fix was added to @tanstack/angular-virtual that refines the typing of the cleanup variable and modifies its assignment to capture the return value of _didMount() via a callback, ensuring event listeners are properly removed on component destruction.

Changes

Cohort / File(s) Summary
Changesets Entry
.changeset/fix-angular-virtual-cleanup.md
Added a patch-level Changesets entry documenting the cleanup fix for event listener removal on component destruction.
Angular Virtual Cleanup Fix
packages/angular-virtual/src/index.ts
Refined cleanup typing from () => void | undefined to (() => void) | undefined and modified the afterNextRender callback to capture _didMount() return value via a deferred assignment instead of direct invocation, ensuring proper cleanup on destroy.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A cleanup bug that caused a leak,
Event listeners refused to speak,
Now captured right, then freed with care,
When components destroy, listeners disappear!
*bounces with glee* 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main fix: capturing the _didMount cleanup to ensure scroll/resize listeners are removed on component destroy.
Description check ✅ Passed The PR description covers the required template sections, explains the root cause and solution clearly, includes a completed checklist with all required items marked, and mentions the changeset generation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 16, 2026

More templates

@tanstack/angular-virtual

npm i https://pkg.pr.new/@tanstack/angular-virtual@1159

@tanstack/lit-virtual

npm i https://pkg.pr.new/@tanstack/lit-virtual@1159

@tanstack/react-virtual

npm i https://pkg.pr.new/@tanstack/react-virtual@1159

@tanstack/solid-virtual

npm i https://pkg.pr.new/@tanstack/solid-virtual@1159

@tanstack/svelte-virtual

npm i https://pkg.pr.new/@tanstack/svelte-virtual@1159

@tanstack/virtual-core

npm i https://pkg.pr.new/@tanstack/virtual-core@1159

@tanstack/vue-virtual

npm i https://pkg.pr.new/@tanstack/vue-virtual@1159

commit: 324a804

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.

1 participant